{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Introduction to DataFrames\n",
    "**[Bogumił Kamiński](http://bogumilkaminski.pl/about/), November 20, 2020**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "using DataFrames"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "using Random"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "Random.seed!(1);"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Manipulating rows of DataFrame"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Selecting rows"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table class=\"data-frame\"><thead><tr><th></th><th>x1</th><th>x2</th><th>x3</th><th>x4</th><th>x5</th></tr><tr><th></th><th>Float64</th><th>Float64</th><th>Float64</th><th>Float64</th><th>Float64</th></tr></thead><tbody><p>4 rows × 5 columns</p><tr><th>1</th><td>0.236033</td><td>0.488613</td><td>0.251662</td><td>0.424718</td><td>0.251379</td></tr><tr><th>2</th><td>0.346517</td><td>0.210968</td><td>0.986666</td><td>0.773223</td><td>0.0203749</td></tr><tr><th>3</th><td>0.312707</td><td>0.951916</td><td>0.555751</td><td>0.28119</td><td>0.287702</td></tr><tr><th>4</th><td>0.00790928</td><td>0.999905</td><td>0.437108</td><td>0.209472</td><td>0.859512</td></tr></tbody></table>"
      ],
      "text/latex": [
       "\\begin{tabular}{r|ccccc}\n",
       "\t& x1 & x2 & x3 & x4 & x5\\\\\n",
       "\t\\hline\n",
       "\t& Float64 & Float64 & Float64 & Float64 & Float64\\\\\n",
       "\t\\hline\n",
       "\t1 & 0.236033 & 0.488613 & 0.251662 & 0.424718 & 0.251379 \\\\\n",
       "\t2 & 0.346517 & 0.210968 & 0.986666 & 0.773223 & 0.0203749 \\\\\n",
       "\t3 & 0.312707 & 0.951916 & 0.555751 & 0.28119 & 0.287702 \\\\\n",
       "\t4 & 0.00790928 & 0.999905 & 0.437108 & 0.209472 & 0.859512 \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/plain": [
       "\u001b[1m4×5 DataFrame\u001b[0m\n",
       "\u001b[1m Row \u001b[0m│\u001b[1m x1         \u001b[0m\u001b[1m x2       \u001b[0m\u001b[1m x3       \u001b[0m\u001b[1m x4       \u001b[0m\u001b[1m x5        \u001b[0m\n",
       "\u001b[1m     \u001b[0m│\u001b[90m Float64    \u001b[0m\u001b[90m Float64  \u001b[0m\u001b[90m Float64  \u001b[0m\u001b[90m Float64  \u001b[0m\u001b[90m Float64   \u001b[0m\n",
       "─────┼─────────────────────────────────────────────────────\n",
       "   1 │ 0.236033    0.488613  0.251662  0.424718  0.251379\n",
       "   2 │ 0.346517    0.210968  0.986666  0.773223  0.0203749\n",
       "   3 │ 0.312707    0.951916  0.555751  0.28119   0.287702\n",
       "   4 │ 0.00790928  0.999905  0.437108  0.209472  0.859512"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = DataFrame(rand(4, 5), :auto)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "using `:` as row selector will copy columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table class=\"data-frame\"><thead><tr><th></th><th>x1</th><th>x2</th><th>x3</th><th>x4</th><th>x5</th></tr><tr><th></th><th>Float64</th><th>Float64</th><th>Float64</th><th>Float64</th><th>Float64</th></tr></thead><tbody><p>4 rows × 5 columns</p><tr><th>1</th><td>0.236033</td><td>0.488613</td><td>0.251662</td><td>0.424718</td><td>0.251379</td></tr><tr><th>2</th><td>0.346517</td><td>0.210968</td><td>0.986666</td><td>0.773223</td><td>0.0203749</td></tr><tr><th>3</th><td>0.312707</td><td>0.951916</td><td>0.555751</td><td>0.28119</td><td>0.287702</td></tr><tr><th>4</th><td>0.00790928</td><td>0.999905</td><td>0.437108</td><td>0.209472</td><td>0.859512</td></tr></tbody></table>"
      ],
      "text/latex": [
       "\\begin{tabular}{r|ccccc}\n",
       "\t& x1 & x2 & x3 & x4 & x5\\\\\n",
       "\t\\hline\n",
       "\t& Float64 & Float64 & Float64 & Float64 & Float64\\\\\n",
       "\t\\hline\n",
       "\t1 & 0.236033 & 0.488613 & 0.251662 & 0.424718 & 0.251379 \\\\\n",
       "\t2 & 0.346517 & 0.210968 & 0.986666 & 0.773223 & 0.0203749 \\\\\n",
       "\t3 & 0.312707 & 0.951916 & 0.555751 & 0.28119 & 0.287702 \\\\\n",
       "\t4 & 0.00790928 & 0.999905 & 0.437108 & 0.209472 & 0.859512 \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/plain": [
       "\u001b[1m4×5 DataFrame\u001b[0m\n",
       "\u001b[1m Row \u001b[0m│\u001b[1m x1         \u001b[0m\u001b[1m x2       \u001b[0m\u001b[1m x3       \u001b[0m\u001b[1m x4       \u001b[0m\u001b[1m x5        \u001b[0m\n",
       "\u001b[1m     \u001b[0m│\u001b[90m Float64    \u001b[0m\u001b[90m Float64  \u001b[0m\u001b[90m Float64  \u001b[0m\u001b[90m Float64  \u001b[0m\u001b[90m Float64   \u001b[0m\n",
       "─────┼─────────────────────────────────────────────────────\n",
       "   1 │ 0.236033    0.488613  0.251662  0.424718  0.251379\n",
       "   2 │ 0.346517    0.210968  0.986666  0.773223  0.0203749\n",
       "   3 │ 0.312707    0.951916  0.555751  0.28119   0.287702\n",
       "   4 │ 0.00790928  0.999905  0.437108  0.209472  0.859512"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[:, :]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "this is the same as"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table class=\"data-frame\"><thead><tr><th></th><th>x1</th><th>x2</th><th>x3</th><th>x4</th><th>x5</th></tr><tr><th></th><th>Float64</th><th>Float64</th><th>Float64</th><th>Float64</th><th>Float64</th></tr></thead><tbody><p>4 rows × 5 columns</p><tr><th>1</th><td>0.236033</td><td>0.488613</td><td>0.251662</td><td>0.424718</td><td>0.251379</td></tr><tr><th>2</th><td>0.346517</td><td>0.210968</td><td>0.986666</td><td>0.773223</td><td>0.0203749</td></tr><tr><th>3</th><td>0.312707</td><td>0.951916</td><td>0.555751</td><td>0.28119</td><td>0.287702</td></tr><tr><th>4</th><td>0.00790928</td><td>0.999905</td><td>0.437108</td><td>0.209472</td><td>0.859512</td></tr></tbody></table>"
      ],
      "text/latex": [
       "\\begin{tabular}{r|ccccc}\n",
       "\t& x1 & x2 & x3 & x4 & x5\\\\\n",
       "\t\\hline\n",
       "\t& Float64 & Float64 & Float64 & Float64 & Float64\\\\\n",
       "\t\\hline\n",
       "\t1 & 0.236033 & 0.488613 & 0.251662 & 0.424718 & 0.251379 \\\\\n",
       "\t2 & 0.346517 & 0.210968 & 0.986666 & 0.773223 & 0.0203749 \\\\\n",
       "\t3 & 0.312707 & 0.951916 & 0.555751 & 0.28119 & 0.287702 \\\\\n",
       "\t4 & 0.00790928 & 0.999905 & 0.437108 & 0.209472 & 0.859512 \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/plain": [
       "\u001b[1m4×5 DataFrame\u001b[0m\n",
       "\u001b[1m Row \u001b[0m│\u001b[1m x1         \u001b[0m\u001b[1m x2       \u001b[0m\u001b[1m x3       \u001b[0m\u001b[1m x4       \u001b[0m\u001b[1m x5        \u001b[0m\n",
       "\u001b[1m     \u001b[0m│\u001b[90m Float64    \u001b[0m\u001b[90m Float64  \u001b[0m\u001b[90m Float64  \u001b[0m\u001b[90m Float64  \u001b[0m\u001b[90m Float64   \u001b[0m\n",
       "─────┼─────────────────────────────────────────────────────\n",
       "   1 │ 0.236033    0.488613  0.251662  0.424718  0.251379\n",
       "   2 │ 0.346517    0.210968  0.986666  0.773223  0.0203749\n",
       "   3 │ 0.312707    0.951916  0.555751  0.28119   0.287702\n",
       "   4 │ 0.00790928  0.999905  0.437108  0.209472  0.859512"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "copy(df)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "you can get a subset of rows of a data frame without copying using `view` to get a `SubDataFrame` "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table class=\"data-frame\"><thead><tr><th></th><th>x1</th><th>x2</th><th>x3</th></tr><tr><th></th><th>Float64</th><th>Float64</th><th>Float64</th></tr></thead><tbody><p>3 rows × 3 columns</p><tr><th>1</th><td>0.236033</td><td>0.488613</td><td>0.251662</td></tr><tr><th>2</th><td>0.346517</td><td>0.210968</td><td>0.986666</td></tr><tr><th>3</th><td>0.312707</td><td>0.951916</td><td>0.555751</td></tr></tbody></table>"
      ],
      "text/latex": [
       "\\begin{tabular}{r|ccc}\n",
       "\t& x1 & x2 & x3\\\\\n",
       "\t\\hline\n",
       "\t& Float64 & Float64 & Float64\\\\\n",
       "\t\\hline\n",
       "\t1 & 0.236033 & 0.488613 & 0.251662 \\\\\n",
       "\t2 & 0.346517 & 0.210968 & 0.986666 \\\\\n",
       "\t3 & 0.312707 & 0.951916 & 0.555751 \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/plain": [
       "\u001b[1m3×3 SubDataFrame\u001b[0m\n",
       "\u001b[1m Row \u001b[0m│\u001b[1m x1       \u001b[0m\u001b[1m x2       \u001b[0m\u001b[1m x3       \u001b[0m\n",
       "\u001b[1m     \u001b[0m│\u001b[90m Float64  \u001b[0m\u001b[90m Float64  \u001b[0m\u001b[90m Float64  \u001b[0m\n",
       "─────┼──────────────────────────────\n",
       "   1 │ 0.236033  0.488613  0.251662\n",
       "   2 │ 0.346517  0.210968  0.986666\n",
       "   3 │ 0.312707  0.951916  0.555751"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sdf = view(df, 1:3, 1:3)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "you still have a detailed reference to the parent"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(\u001b[1m4×5 DataFrame\u001b[0m\n",
       "\u001b[1m Row \u001b[0m│\u001b[1m x1         \u001b[0m\u001b[1m x2       \u001b[0m\u001b[1m x3       \u001b[0m\u001b[1m x4       \u001b[0m\u001b[1m x5        \u001b[0m\n",
       "\u001b[1m     \u001b[0m│\u001b[90m Float64    \u001b[0m\u001b[90m Float64  \u001b[0m\u001b[90m Float64  \u001b[0m\u001b[90m Float64  \u001b[0m\u001b[90m Float64   \u001b[0m\n",
       "─────┼─────────────────────────────────────────────────────\n",
       "   1 │ 0.236033    0.488613  0.251662  0.424718  0.251379\n",
       "   2 │ 0.346517    0.210968  0.986666  0.773223  0.0203749\n",
       "   3 │ 0.312707    0.951916  0.555751  0.28119   0.287702\n",
       "   4 │ 0.00790928  0.999905  0.437108  0.209472  0.859512, (1:3, 1:3))"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "parent(sdf), parentindices(sdf)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "selecting a single row returns a `DataFrameRow` object which is also a view"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<p>DataFrameRow (5 columns)</p><table class=\"data-frame\"><thead><tr><th></th><th>x1</th><th>x2</th><th>x3</th><th>x4</th><th>x5</th></tr><tr><th></th><th>Float64</th><th>Float64</th><th>Float64</th><th>Float64</th><th>Float64</th></tr></thead><tbody><tr><th>3</th><td>0.312707</td><td>0.951916</td><td>0.555751</td><td>0.28119</td><td>0.287702</td></tr></tbody></table>"
      ],
      "text/latex": [
       "\\begin{tabular}{r|ccccc}\n",
       "\t& x1 & x2 & x3 & x4 & x5\\\\\n",
       "\t\\hline\n",
       "\t& Float64 & Float64 & Float64 & Float64 & Float64\\\\\n",
       "\t\\hline\n",
       "\t3 & 0.312707 & 0.951916 & 0.555751 & 0.28119 & 0.287702 \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/plain": [
       "\u001b[1mDataFrameRow\u001b[0m\n",
       "\u001b[1m Row \u001b[0m│\u001b[1m x1       \u001b[0m\u001b[1m x2       \u001b[0m\u001b[1m x3       \u001b[0m\u001b[1m x4      \u001b[0m\u001b[1m x5       \u001b[0m\n",
       "\u001b[1m     \u001b[0m│\u001b[90m Float64  \u001b[0m\u001b[90m Float64  \u001b[0m\u001b[90m Float64  \u001b[0m\u001b[90m Float64 \u001b[0m\u001b[90m Float64  \u001b[0m\n",
       "─────┼─────────────────────────────────────────────────\n",
       "   3 │ 0.312707  0.951916  0.555751  0.28119  0.287702"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dfr = df[3, :]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(\u001b[1m4×5 DataFrame\u001b[0m\n",
       "\u001b[1m Row \u001b[0m│\u001b[1m x1         \u001b[0m\u001b[1m x2       \u001b[0m\u001b[1m x3       \u001b[0m\u001b[1m x4       \u001b[0m\u001b[1m x5        \u001b[0m\n",
       "\u001b[1m     \u001b[0m│\u001b[90m Float64    \u001b[0m\u001b[90m Float64  \u001b[0m\u001b[90m Float64  \u001b[0m\u001b[90m Float64  \u001b[0m\u001b[90m Float64   \u001b[0m\n",
       "─────┼─────────────────────────────────────────────────────\n",
       "   1 │ 0.236033    0.488613  0.251662  0.424718  0.251379\n",
       "   2 │ 0.346517    0.210968  0.986666  0.773223  0.0203749\n",
       "   3 │ 0.312707    0.951916  0.555751  0.28119   0.287702\n",
       "   4 │ 0.00790928  0.999905  0.437108  0.209472  0.859512, (3, Base.OneTo(5)), 3)"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "parent(dfr), parentindices(dfr), rownumber(dfr)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "let us add a column to a data frame by assigning a scalar broadcasting"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4-element Array{Int64,1}:\n",
       " 1\n",
       " 1\n",
       " 1\n",
       " 1"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[!, :Z] .= 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table class=\"data-frame\"><thead><tr><th></th><th>x1</th><th>x2</th><th>x3</th><th>x4</th><th>x5</th><th>Z</th></tr><tr><th></th><th>Float64</th><th>Float64</th><th>Float64</th><th>Float64</th><th>Float64</th><th>Int64</th></tr></thead><tbody><p>4 rows × 6 columns</p><tr><th>1</th><td>0.236033</td><td>0.488613</td><td>0.251662</td><td>0.424718</td><td>0.251379</td><td>1</td></tr><tr><th>2</th><td>0.346517</td><td>0.210968</td><td>0.986666</td><td>0.773223</td><td>0.0203749</td><td>1</td></tr><tr><th>3</th><td>0.312707</td><td>0.951916</td><td>0.555751</td><td>0.28119</td><td>0.287702</td><td>1</td></tr><tr><th>4</th><td>0.00790928</td><td>0.999905</td><td>0.437108</td><td>0.209472</td><td>0.859512</td><td>1</td></tr></tbody></table>"
      ],
      "text/latex": [
       "\\begin{tabular}{r|cccccc}\n",
       "\t& x1 & x2 & x3 & x4 & x5 & Z\\\\\n",
       "\t\\hline\n",
       "\t& Float64 & Float64 & Float64 & Float64 & Float64 & Int64\\\\\n",
       "\t\\hline\n",
       "\t1 & 0.236033 & 0.488613 & 0.251662 & 0.424718 & 0.251379 & 1 \\\\\n",
       "\t2 & 0.346517 & 0.210968 & 0.986666 & 0.773223 & 0.0203749 & 1 \\\\\n",
       "\t3 & 0.312707 & 0.951916 & 0.555751 & 0.28119 & 0.287702 & 1 \\\\\n",
       "\t4 & 0.00790928 & 0.999905 & 0.437108 & 0.209472 & 0.859512 & 1 \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/plain": [
       "\u001b[1m4×6 DataFrame\u001b[0m\n",
       "\u001b[1m Row \u001b[0m│\u001b[1m x1         \u001b[0m\u001b[1m x2       \u001b[0m\u001b[1m x3       \u001b[0m\u001b[1m x4       \u001b[0m\u001b[1m x5        \u001b[0m\u001b[1m Z     \u001b[0m\n",
       "\u001b[1m     \u001b[0m│\u001b[90m Float64    \u001b[0m\u001b[90m Float64  \u001b[0m\u001b[90m Float64  \u001b[0m\u001b[90m Float64  \u001b[0m\u001b[90m Float64   \u001b[0m\u001b[90m Int64 \u001b[0m\n",
       "─────┼────────────────────────────────────────────────────────────\n",
       "   1 │ 0.236033    0.488613  0.251662  0.424718  0.251379       1\n",
       "   2 │ 0.346517    0.210968  0.986666  0.773223  0.0203749      1\n",
       "   3 │ 0.312707    0.951916  0.555751  0.28119   0.287702       1\n",
       "   4 │ 0.00790928  0.999905  0.437108  0.209472  0.859512       1"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Earlier we used `:` for column selection in a view (`SubDataFrame` and `DataFrameRow`).\n",
    "In this case a view will have all columns of the parent after the parent is mutated."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<p>DataFrameRow (6 columns)</p><table class=\"data-frame\"><thead><tr><th></th><th>x1</th><th>x2</th><th>x3</th><th>x4</th><th>x5</th><th>Z</th></tr><tr><th></th><th>Float64</th><th>Float64</th><th>Float64</th><th>Float64</th><th>Float64</th><th>Int64</th></tr></thead><tbody><tr><th>3</th><td>0.312707</td><td>0.951916</td><td>0.555751</td><td>0.28119</td><td>0.287702</td><td>1</td></tr></tbody></table>"
      ],
      "text/latex": [
       "\\begin{tabular}{r|cccccc}\n",
       "\t& x1 & x2 & x3 & x4 & x5 & Z\\\\\n",
       "\t\\hline\n",
       "\t& Float64 & Float64 & Float64 & Float64 & Float64 & Int64\\\\\n",
       "\t\\hline\n",
       "\t3 & 0.312707 & 0.951916 & 0.555751 & 0.28119 & 0.287702 & 1 \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/plain": [
       "\u001b[1mDataFrameRow\u001b[0m\n",
       "\u001b[1m Row \u001b[0m│\u001b[1m x1       \u001b[0m\u001b[1m x2       \u001b[0m\u001b[1m x3       \u001b[0m\u001b[1m x4      \u001b[0m\u001b[1m x5       \u001b[0m\u001b[1m Z     \u001b[0m\n",
       "\u001b[1m     \u001b[0m│\u001b[90m Float64  \u001b[0m\u001b[90m Float64  \u001b[0m\u001b[90m Float64  \u001b[0m\u001b[90m Float64 \u001b[0m\u001b[90m Float64  \u001b[0m\u001b[90m Int64 \u001b[0m\n",
       "─────┼────────────────────────────────────────────────────────\n",
       "   3 │ 0.312707  0.951916  0.555751  0.28119  0.287702      1"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dfr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(\u001b[1m4×6 DataFrame\u001b[0m\n",
       "\u001b[1m Row \u001b[0m│\u001b[1m x1         \u001b[0m\u001b[1m x2       \u001b[0m\u001b[1m x3       \u001b[0m\u001b[1m x4       \u001b[0m\u001b[1m x5        \u001b[0m\u001b[1m Z     \u001b[0m\n",
       "\u001b[1m     \u001b[0m│\u001b[90m Float64    \u001b[0m\u001b[90m Float64  \u001b[0m\u001b[90m Float64  \u001b[0m\u001b[90m Float64  \u001b[0m\u001b[90m Float64   \u001b[0m\u001b[90m Int64 \u001b[0m\n",
       "─────┼────────────────────────────────────────────────────────────\n",
       "   1 │ 0.236033    0.488613  0.251662  0.424718  0.251379       1\n",
       "   2 │ 0.346517    0.210968  0.986666  0.773223  0.0203749      1\n",
       "   3 │ 0.312707    0.951916  0.555751  0.28119   0.287702       1\n",
       "   4 │ 0.00790928  0.999905  0.437108  0.209472  0.859512       1, (3, Base.OneTo(6)), 3)"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "parent(dfr), parentindices(dfr), rownumber(dfr)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Note that `parent` and `parentindices` refer to the true source of data for a `DataFrameRow` and `rownumber` refers to row number in the direct object that was used to create `DataFrameRow`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table class=\"data-frame\"><thead><tr><th></th><th>a</th></tr><tr><th></th><th>Int64</th></tr></thead><tbody><p>4 rows × 1 columns</p><tr><th>1</th><td>1</td></tr><tr><th>2</th><td>2</td></tr><tr><th>3</th><td>3</td></tr><tr><th>4</th><td>4</td></tr></tbody></table>"
      ],
      "text/latex": [
       "\\begin{tabular}{r|c}\n",
       "\t& a\\\\\n",
       "\t\\hline\n",
       "\t& Int64\\\\\n",
       "\t\\hline\n",
       "\t1 & 1 \\\\\n",
       "\t2 & 2 \\\\\n",
       "\t3 & 3 \\\\\n",
       "\t4 & 4 \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/plain": [
       "\u001b[1m4×1 DataFrame\u001b[0m\n",
       "\u001b[1m Row \u001b[0m│\u001b[1m a     \u001b[0m\n",
       "\u001b[1m     \u001b[0m│\u001b[90m Int64 \u001b[0m\n",
       "─────┼───────\n",
       "   1 │     1\n",
       "   2 │     2\n",
       "   3 │     3\n",
       "   4 │     4"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = DataFrame(a=1:4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table class=\"data-frame\"><thead><tr><th></th><th>a</th></tr><tr><th></th><th>Int64</th></tr></thead><tbody><p>2 rows × 1 columns</p><tr><th>1</th><td>3</td></tr><tr><th>2</th><td>2</td></tr></tbody></table>"
      ],
      "text/latex": [
       "\\begin{tabular}{r|c}\n",
       "\t& a\\\\\n",
       "\t\\hline\n",
       "\t& Int64\\\\\n",
       "\t\\hline\n",
       "\t1 & 3 \\\\\n",
       "\t2 & 2 \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/plain": [
       "\u001b[1m2×1 SubDataFrame\u001b[0m\n",
       "\u001b[1m Row \u001b[0m│\u001b[1m a     \u001b[0m\n",
       "\u001b[1m     \u001b[0m│\u001b[90m Int64 \u001b[0m\n",
       "─────┼───────\n",
       "   1 │     3\n",
       "   2 │     2"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dfv = view(df, [3,2], :)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<p>DataFrameRow (1 columns)</p><table class=\"data-frame\"><thead><tr><th></th><th>a</th></tr><tr><th></th><th>Int64</th></tr></thead><tbody><tr><th>3</th><td>3</td></tr></tbody></table>"
      ],
      "text/latex": [
       "\\begin{tabular}{r|c}\n",
       "\t& a\\\\\n",
       "\t\\hline\n",
       "\t& Int64\\\\\n",
       "\t\\hline\n",
       "\t3 & 3 \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/plain": [
       "\u001b[1mDataFrameRow\u001b[0m\n",
       "\u001b[1m Row \u001b[0m│\u001b[1m a     \u001b[0m\n",
       "\u001b[1m     \u001b[0m│\u001b[90m Int64 \u001b[0m\n",
       "─────┼───────\n",
       "   3 │     3"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dfr = dfv[1, :]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(\u001b[1m4×1 DataFrame\u001b[0m\n",
       "\u001b[1m Row \u001b[0m│\u001b[1m a     \u001b[0m\n",
       "\u001b[1m     \u001b[0m│\u001b[90m Int64 \u001b[0m\n",
       "─────┼───────\n",
       "   1 │     1\n",
       "   2 │     2\n",
       "   3 │     3\n",
       "   4 │     4, (3, Base.OneTo(1)), 1)"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "parent(dfr), parentindices(dfr), rownumber(dfr)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Reordering rows"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We create some random data frame (and hope that `x.x` is not sorted :), which is quite likely with 12 rows)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table class=\"data-frame\"><thead><tr><th></th><th>id</th><th>x</th><th>y</th></tr><tr><th></th><th>Int64</th><th>Float64</th><th>Float64</th></tr></thead><tbody><p>12 rows × 3 columns</p><tr><th>1</th><td>1</td><td>0.0769509</td><td>0.0</td></tr><tr><th>2</th><td>2</td><td>0.640396</td><td>0.0</td></tr><tr><th>3</th><td>3</td><td>0.873544</td><td>0.0</td></tr><tr><th>4</th><td>4</td><td>0.278582</td><td>0.0</td></tr><tr><th>5</th><td>5</td><td>0.751313</td><td>0.0</td></tr><tr><th>6</th><td>6</td><td>0.644883</td><td>0.0</td></tr><tr><th>7</th><td>7</td><td>0.0778264</td><td>1.0</td></tr><tr><th>8</th><td>8</td><td>0.848185</td><td>1.0</td></tr><tr><th>9</th><td>9</td><td>0.0856352</td><td>1.0</td></tr><tr><th>10</th><td>10</td><td>0.553206</td><td>1.0</td></tr><tr><th>11</th><td>11</td><td>0.46335</td><td>1.0</td></tr><tr><th>12</th><td>12</td><td>0.185821</td><td>1.0</td></tr></tbody></table>"
      ],
      "text/latex": [
       "\\begin{tabular}{r|ccc}\n",
       "\t& id & x & y\\\\\n",
       "\t\\hline\n",
       "\t& Int64 & Float64 & Float64\\\\\n",
       "\t\\hline\n",
       "\t1 & 1 & 0.0769509 & 0.0 \\\\\n",
       "\t2 & 2 & 0.640396 & 0.0 \\\\\n",
       "\t3 & 3 & 0.873544 & 0.0 \\\\\n",
       "\t4 & 4 & 0.278582 & 0.0 \\\\\n",
       "\t5 & 5 & 0.751313 & 0.0 \\\\\n",
       "\t6 & 6 & 0.644883 & 0.0 \\\\\n",
       "\t7 & 7 & 0.0778264 & 1.0 \\\\\n",
       "\t8 & 8 & 0.848185 & 1.0 \\\\\n",
       "\t9 & 9 & 0.0856352 & 1.0 \\\\\n",
       "\t10 & 10 & 0.553206 & 1.0 \\\\\n",
       "\t11 & 11 & 0.46335 & 1.0 \\\\\n",
       "\t12 & 12 & 0.185821 & 1.0 \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/plain": [
       "\u001b[1m12×3 DataFrame\u001b[0m\n",
       "\u001b[1m Row \u001b[0m│\u001b[1m id    \u001b[0m\u001b[1m x         \u001b[0m\u001b[1m y       \u001b[0m\n",
       "\u001b[1m     \u001b[0m│\u001b[90m Int64 \u001b[0m\u001b[90m Float64   \u001b[0m\u001b[90m Float64 \u001b[0m\n",
       "─────┼───────────────────────────\n",
       "   1 │     1  0.0769509      0.0\n",
       "   2 │     2  0.640396       0.0\n",
       "   3 │     3  0.873544       0.0\n",
       "   4 │     4  0.278582       0.0\n",
       "   5 │     5  0.751313       0.0\n",
       "   6 │     6  0.644883       0.0\n",
       "   7 │     7  0.0778264      1.0\n",
       "   8 │     8  0.848185       1.0\n",
       "   9 │     9  0.0856352      1.0\n",
       "  10 │    10  0.553206       1.0\n",
       "  11 │    11  0.46335        1.0\n",
       "  12 │    12  0.185821       1.0"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x = DataFrame(id=1:12, x = rand(12), y = [zeros(6); ones(6)])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "check if a DataFrame or a subset of its columns is sorted"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(true, false)"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "issorted(x), issorted(x, :x)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "we sort x in place"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table class=\"data-frame\"><thead><tr><th></th><th>id</th><th>x</th><th>y</th></tr><tr><th></th><th>Int64</th><th>Float64</th><th>Float64</th></tr></thead><tbody><p>12 rows × 3 columns</p><tr><th>1</th><td>1</td><td>0.0769509</td><td>0.0</td></tr><tr><th>2</th><td>7</td><td>0.0778264</td><td>1.0</td></tr><tr><th>3</th><td>9</td><td>0.0856352</td><td>1.0</td></tr><tr><th>4</th><td>12</td><td>0.185821</td><td>1.0</td></tr><tr><th>5</th><td>4</td><td>0.278582</td><td>0.0</td></tr><tr><th>6</th><td>11</td><td>0.46335</td><td>1.0</td></tr><tr><th>7</th><td>10</td><td>0.553206</td><td>1.0</td></tr><tr><th>8</th><td>2</td><td>0.640396</td><td>0.0</td></tr><tr><th>9</th><td>6</td><td>0.644883</td><td>0.0</td></tr><tr><th>10</th><td>5</td><td>0.751313</td><td>0.0</td></tr><tr><th>11</th><td>8</td><td>0.848185</td><td>1.0</td></tr><tr><th>12</th><td>3</td><td>0.873544</td><td>0.0</td></tr></tbody></table>"
      ],
      "text/latex": [
       "\\begin{tabular}{r|ccc}\n",
       "\t& id & x & y\\\\\n",
       "\t\\hline\n",
       "\t& Int64 & Float64 & Float64\\\\\n",
       "\t\\hline\n",
       "\t1 & 1 & 0.0769509 & 0.0 \\\\\n",
       "\t2 & 7 & 0.0778264 & 1.0 \\\\\n",
       "\t3 & 9 & 0.0856352 & 1.0 \\\\\n",
       "\t4 & 12 & 0.185821 & 1.0 \\\\\n",
       "\t5 & 4 & 0.278582 & 0.0 \\\\\n",
       "\t6 & 11 & 0.46335 & 1.0 \\\\\n",
       "\t7 & 10 & 0.553206 & 1.0 \\\\\n",
       "\t8 & 2 & 0.640396 & 0.0 \\\\\n",
       "\t9 & 6 & 0.644883 & 0.0 \\\\\n",
       "\t10 & 5 & 0.751313 & 0.0 \\\\\n",
       "\t11 & 8 & 0.848185 & 1.0 \\\\\n",
       "\t12 & 3 & 0.873544 & 0.0 \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/plain": [
       "\u001b[1m12×3 DataFrame\u001b[0m\n",
       "\u001b[1m Row \u001b[0m│\u001b[1m id    \u001b[0m\u001b[1m x         \u001b[0m\u001b[1m y       \u001b[0m\n",
       "\u001b[1m     \u001b[0m│\u001b[90m Int64 \u001b[0m\u001b[90m Float64   \u001b[0m\u001b[90m Float64 \u001b[0m\n",
       "─────┼───────────────────────────\n",
       "   1 │     1  0.0769509      0.0\n",
       "   2 │     7  0.0778264      1.0\n",
       "   3 │     9  0.0856352      1.0\n",
       "   4 │    12  0.185821       1.0\n",
       "   5 │     4  0.278582       0.0\n",
       "   6 │    11  0.46335        1.0\n",
       "   7 │    10  0.553206       1.0\n",
       "   8 │     2  0.640396       0.0\n",
       "   9 │     6  0.644883       0.0\n",
       "  10 │     5  0.751313       0.0\n",
       "  11 │     8  0.848185       1.0\n",
       "  12 │     3  0.873544       0.0"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sort!(x, :x)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "now we create a new DataFrame"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table class=\"data-frame\"><thead><tr><th></th><th>id</th><th>x</th><th>y</th></tr><tr><th></th><th>Int64</th><th>Float64</th><th>Float64</th></tr></thead><tbody><p>12 rows × 3 columns</p><tr><th>1</th><td>1</td><td>0.0769509</td><td>0.0</td></tr><tr><th>2</th><td>2</td><td>0.640396</td><td>0.0</td></tr><tr><th>3</th><td>3</td><td>0.873544</td><td>0.0</td></tr><tr><th>4</th><td>4</td><td>0.278582</td><td>0.0</td></tr><tr><th>5</th><td>5</td><td>0.751313</td><td>0.0</td></tr><tr><th>6</th><td>6</td><td>0.644883</td><td>0.0</td></tr><tr><th>7</th><td>7</td><td>0.0778264</td><td>1.0</td></tr><tr><th>8</th><td>8</td><td>0.848185</td><td>1.0</td></tr><tr><th>9</th><td>9</td><td>0.0856352</td><td>1.0</td></tr><tr><th>10</th><td>10</td><td>0.553206</td><td>1.0</td></tr><tr><th>11</th><td>11</td><td>0.46335</td><td>1.0</td></tr><tr><th>12</th><td>12</td><td>0.185821</td><td>1.0</td></tr></tbody></table>"
      ],
      "text/latex": [
       "\\begin{tabular}{r|ccc}\n",
       "\t& id & x & y\\\\\n",
       "\t\\hline\n",
       "\t& Int64 & Float64 & Float64\\\\\n",
       "\t\\hline\n",
       "\t1 & 1 & 0.0769509 & 0.0 \\\\\n",
       "\t2 & 2 & 0.640396 & 0.0 \\\\\n",
       "\t3 & 3 & 0.873544 & 0.0 \\\\\n",
       "\t4 & 4 & 0.278582 & 0.0 \\\\\n",
       "\t5 & 5 & 0.751313 & 0.0 \\\\\n",
       "\t6 & 6 & 0.644883 & 0.0 \\\\\n",
       "\t7 & 7 & 0.0778264 & 1.0 \\\\\n",
       "\t8 & 8 & 0.848185 & 1.0 \\\\\n",
       "\t9 & 9 & 0.0856352 & 1.0 \\\\\n",
       "\t10 & 10 & 0.553206 & 1.0 \\\\\n",
       "\t11 & 11 & 0.46335 & 1.0 \\\\\n",
       "\t12 & 12 & 0.185821 & 1.0 \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/plain": [
       "\u001b[1m12×3 DataFrame\u001b[0m\n",
       "\u001b[1m Row \u001b[0m│\u001b[1m id    \u001b[0m\u001b[1m x         \u001b[0m\u001b[1m y       \u001b[0m\n",
       "\u001b[1m     \u001b[0m│\u001b[90m Int64 \u001b[0m\u001b[90m Float64   \u001b[0m\u001b[90m Float64 \u001b[0m\n",
       "─────┼───────────────────────────\n",
       "   1 │     1  0.0769509      0.0\n",
       "   2 │     2  0.640396       0.0\n",
       "   3 │     3  0.873544       0.0\n",
       "   4 │     4  0.278582       0.0\n",
       "   5 │     5  0.751313       0.0\n",
       "   6 │     6  0.644883       0.0\n",
       "   7 │     7  0.0778264      1.0\n",
       "   8 │     8  0.848185       1.0\n",
       "   9 │     9  0.0856352      1.0\n",
       "  10 │    10  0.553206       1.0\n",
       "  11 │    11  0.46335        1.0\n",
       "  12 │    12  0.185821       1.0"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "y = sort(x, :id)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "here we sort by two columns, first is decreasing, second is increasing"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table class=\"data-frame\"><thead><tr><th></th><th>id</th><th>x</th><th>y</th></tr><tr><th></th><th>Int64</th><th>Float64</th><th>Float64</th></tr></thead><tbody><p>12 rows × 3 columns</p><tr><th>1</th><td>7</td><td>0.0778264</td><td>1.0</td></tr><tr><th>2</th><td>9</td><td>0.0856352</td><td>1.0</td></tr><tr><th>3</th><td>12</td><td>0.185821</td><td>1.0</td></tr><tr><th>4</th><td>11</td><td>0.46335</td><td>1.0</td></tr><tr><th>5</th><td>10</td><td>0.553206</td><td>1.0</td></tr><tr><th>6</th><td>8</td><td>0.848185</td><td>1.0</td></tr><tr><th>7</th><td>1</td><td>0.0769509</td><td>0.0</td></tr><tr><th>8</th><td>4</td><td>0.278582</td><td>0.0</td></tr><tr><th>9</th><td>2</td><td>0.640396</td><td>0.0</td></tr><tr><th>10</th><td>6</td><td>0.644883</td><td>0.0</td></tr><tr><th>11</th><td>5</td><td>0.751313</td><td>0.0</td></tr><tr><th>12</th><td>3</td><td>0.873544</td><td>0.0</td></tr></tbody></table>"
      ],
      "text/latex": [
       "\\begin{tabular}{r|ccc}\n",
       "\t& id & x & y\\\\\n",
       "\t\\hline\n",
       "\t& Int64 & Float64 & Float64\\\\\n",
       "\t\\hline\n",
       "\t1 & 7 & 0.0778264 & 1.0 \\\\\n",
       "\t2 & 9 & 0.0856352 & 1.0 \\\\\n",
       "\t3 & 12 & 0.185821 & 1.0 \\\\\n",
       "\t4 & 11 & 0.46335 & 1.0 \\\\\n",
       "\t5 & 10 & 0.553206 & 1.0 \\\\\n",
       "\t6 & 8 & 0.848185 & 1.0 \\\\\n",
       "\t7 & 1 & 0.0769509 & 0.0 \\\\\n",
       "\t8 & 4 & 0.278582 & 0.0 \\\\\n",
       "\t9 & 2 & 0.640396 & 0.0 \\\\\n",
       "\t10 & 6 & 0.644883 & 0.0 \\\\\n",
       "\t11 & 5 & 0.751313 & 0.0 \\\\\n",
       "\t12 & 3 & 0.873544 & 0.0 \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/plain": [
       "\u001b[1m12×3 DataFrame\u001b[0m\n",
       "\u001b[1m Row \u001b[0m│\u001b[1m id    \u001b[0m\u001b[1m x         \u001b[0m\u001b[1m y       \u001b[0m\n",
       "\u001b[1m     \u001b[0m│\u001b[90m Int64 \u001b[0m\u001b[90m Float64   \u001b[0m\u001b[90m Float64 \u001b[0m\n",
       "─────┼───────────────────────────\n",
       "   1 │     7  0.0778264      1.0\n",
       "   2 │     9  0.0856352      1.0\n",
       "   3 │    12  0.185821       1.0\n",
       "   4 │    11  0.46335        1.0\n",
       "   5 │    10  0.553206       1.0\n",
       "   6 │     8  0.848185       1.0\n",
       "   7 │     1  0.0769509      0.0\n",
       "   8 │     4  0.278582       0.0\n",
       "   9 │     2  0.640396       0.0\n",
       "  10 │     6  0.644883       0.0\n",
       "  11 │     5  0.751313       0.0\n",
       "  12 │     3  0.873544       0.0"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sort(x, [:y, :x], rev=[true, false])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table class=\"data-frame\"><thead><tr><th></th><th>id</th><th>x</th><th>y</th></tr><tr><th></th><th>Int64</th><th>Float64</th><th>Float64</th></tr></thead><tbody><p>12 rows × 3 columns</p><tr><th>1</th><td>7</td><td>0.0778264</td><td>1.0</td></tr><tr><th>2</th><td>9</td><td>0.0856352</td><td>1.0</td></tr><tr><th>3</th><td>12</td><td>0.185821</td><td>1.0</td></tr><tr><th>4</th><td>11</td><td>0.46335</td><td>1.0</td></tr><tr><th>5</th><td>10</td><td>0.553206</td><td>1.0</td></tr><tr><th>6</th><td>8</td><td>0.848185</td><td>1.0</td></tr><tr><th>7</th><td>1</td><td>0.0769509</td><td>0.0</td></tr><tr><th>8</th><td>4</td><td>0.278582</td><td>0.0</td></tr><tr><th>9</th><td>2</td><td>0.640396</td><td>0.0</td></tr><tr><th>10</th><td>6</td><td>0.644883</td><td>0.0</td></tr><tr><th>11</th><td>5</td><td>0.751313</td><td>0.0</td></tr><tr><th>12</th><td>3</td><td>0.873544</td><td>0.0</td></tr></tbody></table>"
      ],
      "text/latex": [
       "\\begin{tabular}{r|ccc}\n",
       "\t& id & x & y\\\\\n",
       "\t\\hline\n",
       "\t& Int64 & Float64 & Float64\\\\\n",
       "\t\\hline\n",
       "\t1 & 7 & 0.0778264 & 1.0 \\\\\n",
       "\t2 & 9 & 0.0856352 & 1.0 \\\\\n",
       "\t3 & 12 & 0.185821 & 1.0 \\\\\n",
       "\t4 & 11 & 0.46335 & 1.0 \\\\\n",
       "\t5 & 10 & 0.553206 & 1.0 \\\\\n",
       "\t6 & 8 & 0.848185 & 1.0 \\\\\n",
       "\t7 & 1 & 0.0769509 & 0.0 \\\\\n",
       "\t8 & 4 & 0.278582 & 0.0 \\\\\n",
       "\t9 & 2 & 0.640396 & 0.0 \\\\\n",
       "\t10 & 6 & 0.644883 & 0.0 \\\\\n",
       "\t11 & 5 & 0.751313 & 0.0 \\\\\n",
       "\t12 & 3 & 0.873544 & 0.0 \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/plain": [
       "\u001b[1m12×3 DataFrame\u001b[0m\n",
       "\u001b[1m Row \u001b[0m│\u001b[1m id    \u001b[0m\u001b[1m x         \u001b[0m\u001b[1m y       \u001b[0m\n",
       "\u001b[1m     \u001b[0m│\u001b[90m Int64 \u001b[0m\u001b[90m Float64   \u001b[0m\u001b[90m Float64 \u001b[0m\n",
       "─────┼───────────────────────────\n",
       "   1 │     7  0.0778264      1.0\n",
       "   2 │     9  0.0856352      1.0\n",
       "   3 │    12  0.185821       1.0\n",
       "   4 │    11  0.46335        1.0\n",
       "   5 │    10  0.553206       1.0\n",
       "   6 │     8  0.848185       1.0\n",
       "   7 │     1  0.0769509      0.0\n",
       "   8 │     4  0.278582       0.0\n",
       "   9 │     2  0.640396       0.0\n",
       "  10 │     6  0.644883       0.0\n",
       "  11 │     5  0.751313       0.0\n",
       "  12 │     3  0.873544       0.0"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sort(x, [order(:y, rev=true), :x]) # the same as above"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "now we try some more fancy sorting stuff"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table class=\"data-frame\"><thead><tr><th></th><th>id</th><th>x</th><th>y</th></tr><tr><th></th><th>Int64</th><th>Float64</th><th>Float64</th></tr></thead><tbody><p>12 rows × 3 columns</p><tr><th>1</th><td>8</td><td>0.848185</td><td>1.0</td></tr><tr><th>2</th><td>10</td><td>0.553206</td><td>1.0</td></tr><tr><th>3</th><td>11</td><td>0.46335</td><td>1.0</td></tr><tr><th>4</th><td>12</td><td>0.185821</td><td>1.0</td></tr><tr><th>5</th><td>9</td><td>0.0856352</td><td>1.0</td></tr><tr><th>6</th><td>7</td><td>0.0778264</td><td>1.0</td></tr><tr><th>7</th><td>3</td><td>0.873544</td><td>0.0</td></tr><tr><th>8</th><td>5</td><td>0.751313</td><td>0.0</td></tr><tr><th>9</th><td>6</td><td>0.644883</td><td>0.0</td></tr><tr><th>10</th><td>2</td><td>0.640396</td><td>0.0</td></tr><tr><th>11</th><td>4</td><td>0.278582</td><td>0.0</td></tr><tr><th>12</th><td>1</td><td>0.0769509</td><td>0.0</td></tr></tbody></table>"
      ],
      "text/latex": [
       "\\begin{tabular}{r|ccc}\n",
       "\t& id & x & y\\\\\n",
       "\t\\hline\n",
       "\t& Int64 & Float64 & Float64\\\\\n",
       "\t\\hline\n",
       "\t1 & 8 & 0.848185 & 1.0 \\\\\n",
       "\t2 & 10 & 0.553206 & 1.0 \\\\\n",
       "\t3 & 11 & 0.46335 & 1.0 \\\\\n",
       "\t4 & 12 & 0.185821 & 1.0 \\\\\n",
       "\t5 & 9 & 0.0856352 & 1.0 \\\\\n",
       "\t6 & 7 & 0.0778264 & 1.0 \\\\\n",
       "\t7 & 3 & 0.873544 & 0.0 \\\\\n",
       "\t8 & 5 & 0.751313 & 0.0 \\\\\n",
       "\t9 & 6 & 0.644883 & 0.0 \\\\\n",
       "\t10 & 2 & 0.640396 & 0.0 \\\\\n",
       "\t11 & 4 & 0.278582 & 0.0 \\\\\n",
       "\t12 & 1 & 0.0769509 & 0.0 \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/plain": [
       "\u001b[1m12×3 DataFrame\u001b[0m\n",
       "\u001b[1m Row \u001b[0m│\u001b[1m id    \u001b[0m\u001b[1m x         \u001b[0m\u001b[1m y       \u001b[0m\n",
       "\u001b[1m     \u001b[0m│\u001b[90m Int64 \u001b[0m\u001b[90m Float64   \u001b[0m\u001b[90m Float64 \u001b[0m\n",
       "─────┼───────────────────────────\n",
       "   1 │     8  0.848185       1.0\n",
       "   2 │    10  0.553206       1.0\n",
       "   3 │    11  0.46335        1.0\n",
       "   4 │    12  0.185821       1.0\n",
       "   5 │     9  0.0856352      1.0\n",
       "   6 │     7  0.0778264      1.0\n",
       "   7 │     3  0.873544       0.0\n",
       "   8 │     5  0.751313       0.0\n",
       "   9 │     6  0.644883       0.0\n",
       "  10 │     2  0.640396       0.0\n",
       "  11 │     4  0.278582       0.0\n",
       "  12 │     1  0.0769509      0.0"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sort(x, [order(:y, rev=true), order(:x, by=v->-v)])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "this is how you can reorder rows (here randomly)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table class=\"data-frame\"><thead><tr><th></th><th>id</th><th>x</th><th>y</th></tr><tr><th></th><th>Int64</th><th>Float64</th><th>Float64</th></tr></thead><tbody><p>10 rows × 3 columns</p><tr><th>1</th><td>12</td><td>0.185821</td><td>1.0</td></tr><tr><th>2</th><td>11</td><td>0.46335</td><td>1.0</td></tr><tr><th>3</th><td>6</td><td>0.644883</td><td>0.0</td></tr><tr><th>4</th><td>2</td><td>0.640396</td><td>0.0</td></tr><tr><th>5</th><td>1</td><td>0.0769509</td><td>0.0</td></tr><tr><th>6</th><td>10</td><td>0.553206</td><td>1.0</td></tr><tr><th>7</th><td>7</td><td>0.0778264</td><td>1.0</td></tr><tr><th>8</th><td>4</td><td>0.278582</td><td>0.0</td></tr><tr><th>9</th><td>9</td><td>0.0856352</td><td>1.0</td></tr><tr><th>10</th><td>5</td><td>0.751313</td><td>0.0</td></tr></tbody></table>"
      ],
      "text/latex": [
       "\\begin{tabular}{r|ccc}\n",
       "\t& id & x & y\\\\\n",
       "\t\\hline\n",
       "\t& Int64 & Float64 & Float64\\\\\n",
       "\t\\hline\n",
       "\t1 & 12 & 0.185821 & 1.0 \\\\\n",
       "\t2 & 11 & 0.46335 & 1.0 \\\\\n",
       "\t3 & 6 & 0.644883 & 0.0 \\\\\n",
       "\t4 & 2 & 0.640396 & 0.0 \\\\\n",
       "\t5 & 1 & 0.0769509 & 0.0 \\\\\n",
       "\t6 & 10 & 0.553206 & 1.0 \\\\\n",
       "\t7 & 7 & 0.0778264 & 1.0 \\\\\n",
       "\t8 & 4 & 0.278582 & 0.0 \\\\\n",
       "\t9 & 9 & 0.0856352 & 1.0 \\\\\n",
       "\t10 & 5 & 0.751313 & 0.0 \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/plain": [
       "\u001b[1m10×3 DataFrame\u001b[0m\n",
       "\u001b[1m Row \u001b[0m│\u001b[1m id    \u001b[0m\u001b[1m x         \u001b[0m\u001b[1m y       \u001b[0m\n",
       "\u001b[1m     \u001b[0m│\u001b[90m Int64 \u001b[0m\u001b[90m Float64   \u001b[0m\u001b[90m Float64 \u001b[0m\n",
       "─────┼───────────────────────────\n",
       "   1 │    12  0.185821       1.0\n",
       "   2 │    11  0.46335        1.0\n",
       "   3 │     6  0.644883       0.0\n",
       "   4 │     2  0.640396       0.0\n",
       "   5 │     1  0.0769509      0.0\n",
       "   6 │    10  0.553206       1.0\n",
       "   7 │     7  0.0778264      1.0\n",
       "   8 │     4  0.278582       0.0\n",
       "   9 │     9  0.0856352      1.0\n",
       "  10 │     5  0.751313       0.0"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x[shuffle(1:10), :]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    " it is also easy to swap rows using broadcasted assignment"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table class=\"data-frame\"><thead><tr><th></th><th>id</th><th>x</th><th>y</th></tr><tr><th></th><th>Int64</th><th>Float64</th><th>Float64</th></tr></thead><tbody><p>12 rows × 3 columns</p><tr><th>1</th><td>10</td><td>0.553206</td><td>1.0</td></tr><tr><th>2</th><td>2</td><td>0.640396</td><td>0.0</td></tr><tr><th>3</th><td>3</td><td>0.873544</td><td>0.0</td></tr><tr><th>4</th><td>4</td><td>0.278582</td><td>0.0</td></tr><tr><th>5</th><td>5</td><td>0.751313</td><td>0.0</td></tr><tr><th>6</th><td>6</td><td>0.644883</td><td>0.0</td></tr><tr><th>7</th><td>7</td><td>0.0778264</td><td>1.0</td></tr><tr><th>8</th><td>8</td><td>0.848185</td><td>1.0</td></tr><tr><th>9</th><td>9</td><td>0.0856352</td><td>1.0</td></tr><tr><th>10</th><td>1</td><td>0.0769509</td><td>0.0</td></tr><tr><th>11</th><td>11</td><td>0.46335</td><td>1.0</td></tr><tr><th>12</th><td>12</td><td>0.185821</td><td>1.0</td></tr></tbody></table>"
      ],
      "text/latex": [
       "\\begin{tabular}{r|ccc}\n",
       "\t& id & x & y\\\\\n",
       "\t\\hline\n",
       "\t& Int64 & Float64 & Float64\\\\\n",
       "\t\\hline\n",
       "\t1 & 10 & 0.553206 & 1.0 \\\\\n",
       "\t2 & 2 & 0.640396 & 0.0 \\\\\n",
       "\t3 & 3 & 0.873544 & 0.0 \\\\\n",
       "\t4 & 4 & 0.278582 & 0.0 \\\\\n",
       "\t5 & 5 & 0.751313 & 0.0 \\\\\n",
       "\t6 & 6 & 0.644883 & 0.0 \\\\\n",
       "\t7 & 7 & 0.0778264 & 1.0 \\\\\n",
       "\t8 & 8 & 0.848185 & 1.0 \\\\\n",
       "\t9 & 9 & 0.0856352 & 1.0 \\\\\n",
       "\t10 & 1 & 0.0769509 & 0.0 \\\\\n",
       "\t11 & 11 & 0.46335 & 1.0 \\\\\n",
       "\t12 & 12 & 0.185821 & 1.0 \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/plain": [
       "\u001b[1m12×3 DataFrame\u001b[0m\n",
       "\u001b[1m Row \u001b[0m│\u001b[1m id    \u001b[0m\u001b[1m x         \u001b[0m\u001b[1m y       \u001b[0m\n",
       "\u001b[1m     \u001b[0m│\u001b[90m Int64 \u001b[0m\u001b[90m Float64   \u001b[0m\u001b[90m Float64 \u001b[0m\n",
       "─────┼───────────────────────────\n",
       "   1 │    10  0.553206       1.0\n",
       "   2 │     2  0.640396       0.0\n",
       "   3 │     3  0.873544       0.0\n",
       "   4 │     4  0.278582       0.0\n",
       "   5 │     5  0.751313       0.0\n",
       "   6 │     6  0.644883       0.0\n",
       "   7 │     7  0.0778264      1.0\n",
       "   8 │     8  0.848185       1.0\n",
       "   9 │     9  0.0856352      1.0\n",
       "  10 │     1  0.0769509      0.0\n",
       "  11 │    11  0.46335        1.0\n",
       "  12 │    12  0.185821       1.0"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sort!(x, :id)\n",
    "x[[1,10],:] .= x[[10,1],:]\n",
    "x"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table class=\"data-frame\"><thead><tr><th></th><th>id</th><th>x</th><th>y</th></tr><tr><th></th><th>Int64</th><th>Float64</th><th>Float64</th></tr></thead><tbody><p>12 rows × 3 columns</p><tr><th>1</th><td>10</td><td>0.553206</td><td>1.0</td></tr><tr><th>2</th><td>2</td><td>0.640396</td><td>0.0</td></tr><tr><th>3</th><td>3</td><td>0.873544</td><td>0.0</td></tr><tr><th>4</th><td>4</td><td>0.278582</td><td>0.0</td></tr><tr><th>5</th><td>5</td><td>0.751313</td><td>0.0</td></tr><tr><th>6</th><td>6</td><td>0.644883</td><td>0.0</td></tr><tr><th>7</th><td>7</td><td>0.0778264</td><td>1.0</td></tr><tr><th>8</th><td>8</td><td>0.848185</td><td>1.0</td></tr><tr><th>9</th><td>9</td><td>0.0856352</td><td>1.0</td></tr><tr><th>10</th><td>1</td><td>0.0769509</td><td>0.0</td></tr><tr><th>11</th><td>11</td><td>0.46335</td><td>1.0</td></tr><tr><th>12</th><td>12</td><td>0.185821</td><td>1.0</td></tr></tbody></table>"
      ],
      "text/latex": [
       "\\begin{tabular}{r|ccc}\n",
       "\t& id & x & y\\\\\n",
       "\t\\hline\n",
       "\t& Int64 & Float64 & Float64\\\\\n",
       "\t\\hline\n",
       "\t1 & 10 & 0.553206 & 1.0 \\\\\n",
       "\t2 & 2 & 0.640396 & 0.0 \\\\\n",
       "\t3 & 3 & 0.873544 & 0.0 \\\\\n",
       "\t4 & 4 & 0.278582 & 0.0 \\\\\n",
       "\t5 & 5 & 0.751313 & 0.0 \\\\\n",
       "\t6 & 6 & 0.644883 & 0.0 \\\\\n",
       "\t7 & 7 & 0.0778264 & 1.0 \\\\\n",
       "\t8 & 8 & 0.848185 & 1.0 \\\\\n",
       "\t9 & 9 & 0.0856352 & 1.0 \\\\\n",
       "\t10 & 1 & 0.0769509 & 0.0 \\\\\n",
       "\t11 & 11 & 0.46335 & 1.0 \\\\\n",
       "\t12 & 12 & 0.185821 & 1.0 \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/plain": [
       "\u001b[1m12×3 DataFrame\u001b[0m\n",
       "\u001b[1m Row \u001b[0m│\u001b[1m id    \u001b[0m\u001b[1m x         \u001b[0m\u001b[1m y       \u001b[0m\n",
       "\u001b[1m     \u001b[0m│\u001b[90m Int64 \u001b[0m\u001b[90m Float64   \u001b[0m\u001b[90m Float64 \u001b[0m\n",
       "─────┼───────────────────────────\n",
       "   1 │    10  0.553206       1.0\n",
       "   2 │     2  0.640396       0.0\n",
       "   3 │     3  0.873544       0.0\n",
       "   4 │     4  0.278582       0.0\n",
       "   5 │     5  0.751313       0.0\n",
       "   6 │     6  0.644883       0.0\n",
       "   7 │     7  0.0778264      1.0\n",
       "   8 │     8  0.848185       1.0\n",
       "   9 │     9  0.0856352      1.0\n",
       "  10 │     1  0.0769509      0.0\n",
       "  11 │    11  0.46335        1.0\n",
       "  12 │    12  0.185821       1.0"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Merging/adding rows"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table class=\"data-frame\"><thead><tr><th></th><th>x1</th><th>x2</th><th>x3</th><th>x4</th><th>x5</th></tr><tr><th></th><th>Float64</th><th>Float64</th><th>Float64</th><th>Float64</th><th>Float64</th></tr></thead><tbody><p>3 rows × 5 columns</p><tr><th>1</th><td>0.440897</td><td>0.953803</td><td>0.0135403</td><td>0.596537</td><td>0.548635</td></tr><tr><th>2</th><td>0.404673</td><td>0.0951856</td><td>0.303399</td><td>0.638935</td><td>0.262992</td></tr><tr><th>3</th><td>0.736787</td><td>0.519675</td><td>0.702557</td><td>0.872347</td><td>0.526443</td></tr></tbody></table>"
      ],
      "text/latex": [
       "\\begin{tabular}{r|ccccc}\n",
       "\t& x1 & x2 & x3 & x4 & x5\\\\\n",
       "\t\\hline\n",
       "\t& Float64 & Float64 & Float64 & Float64 & Float64\\\\\n",
       "\t\\hline\n",
       "\t1 & 0.440897 & 0.953803 & 0.0135403 & 0.596537 & 0.548635 \\\\\n",
       "\t2 & 0.404673 & 0.0951856 & 0.303399 & 0.638935 & 0.262992 \\\\\n",
       "\t3 & 0.736787 & 0.519675 & 0.702557 & 0.872347 & 0.526443 \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/plain": [
       "\u001b[1m3×5 DataFrame\u001b[0m\n",
       "\u001b[1m Row \u001b[0m│\u001b[1m x1       \u001b[0m\u001b[1m x2        \u001b[0m\u001b[1m x3        \u001b[0m\u001b[1m x4       \u001b[0m\u001b[1m x5       \u001b[0m\n",
       "\u001b[1m     \u001b[0m│\u001b[90m Float64  \u001b[0m\u001b[90m Float64   \u001b[0m\u001b[90m Float64   \u001b[0m\u001b[90m Float64  \u001b[0m\u001b[90m Float64  \u001b[0m\n",
       "─────┼────────────────────────────────────────────────────\n",
       "   1 │ 0.440897  0.953803   0.0135403  0.596537  0.548635\n",
       "   2 │ 0.404673  0.0951856  0.303399   0.638935  0.262992\n",
       "   3 │ 0.736787  0.519675   0.702557   0.872347  0.526443"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x = DataFrame(rand(3, 5), :auto)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "merge by rows - data frames must have the same column names; the same is `vcat`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table class=\"data-frame\"><thead><tr><th></th><th>x1</th><th>x2</th><th>x3</th><th>x4</th><th>x5</th></tr><tr><th></th><th>Float64</th><th>Float64</th><th>Float64</th><th>Float64</th><th>Float64</th></tr></thead><tbody><p>6 rows × 5 columns</p><tr><th>1</th><td>0.440897</td><td>0.953803</td><td>0.0135403</td><td>0.596537</td><td>0.548635</td></tr><tr><th>2</th><td>0.404673</td><td>0.0951856</td><td>0.303399</td><td>0.638935</td><td>0.262992</td></tr><tr><th>3</th><td>0.736787</td><td>0.519675</td><td>0.702557</td><td>0.872347</td><td>0.526443</td></tr><tr><th>4</th><td>0.440897</td><td>0.953803</td><td>0.0135403</td><td>0.596537</td><td>0.548635</td></tr><tr><th>5</th><td>0.404673</td><td>0.0951856</td><td>0.303399</td><td>0.638935</td><td>0.262992</td></tr><tr><th>6</th><td>0.736787</td><td>0.519675</td><td>0.702557</td><td>0.872347</td><td>0.526443</td></tr></tbody></table>"
      ],
      "text/latex": [
       "\\begin{tabular}{r|ccccc}\n",
       "\t& x1 & x2 & x3 & x4 & x5\\\\\n",
       "\t\\hline\n",
       "\t& Float64 & Float64 & Float64 & Float64 & Float64\\\\\n",
       "\t\\hline\n",
       "\t1 & 0.440897 & 0.953803 & 0.0135403 & 0.596537 & 0.548635 \\\\\n",
       "\t2 & 0.404673 & 0.0951856 & 0.303399 & 0.638935 & 0.262992 \\\\\n",
       "\t3 & 0.736787 & 0.519675 & 0.702557 & 0.872347 & 0.526443 \\\\\n",
       "\t4 & 0.440897 & 0.953803 & 0.0135403 & 0.596537 & 0.548635 \\\\\n",
       "\t5 & 0.404673 & 0.0951856 & 0.303399 & 0.638935 & 0.262992 \\\\\n",
       "\t6 & 0.736787 & 0.519675 & 0.702557 & 0.872347 & 0.526443 \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/plain": [
       "\u001b[1m6×5 DataFrame\u001b[0m\n",
       "\u001b[1m Row \u001b[0m│\u001b[1m x1       \u001b[0m\u001b[1m x2        \u001b[0m\u001b[1m x3        \u001b[0m\u001b[1m x4       \u001b[0m\u001b[1m x5       \u001b[0m\n",
       "\u001b[1m     \u001b[0m│\u001b[90m Float64  \u001b[0m\u001b[90m Float64   \u001b[0m\u001b[90m Float64   \u001b[0m\u001b[90m Float64  \u001b[0m\u001b[90m Float64  \u001b[0m\n",
       "─────┼────────────────────────────────────────────────────\n",
       "   1 │ 0.440897  0.953803   0.0135403  0.596537  0.548635\n",
       "   2 │ 0.404673  0.0951856  0.303399   0.638935  0.262992\n",
       "   3 │ 0.736787  0.519675   0.702557   0.872347  0.526443\n",
       "   4 │ 0.440897  0.953803   0.0135403  0.596537  0.548635\n",
       "   5 │ 0.404673  0.0951856  0.303399   0.638935  0.262992\n",
       "   6 │ 0.736787  0.519675   0.702557   0.872347  0.526443"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "[x; x]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "you can efficiently `vcat` a vector of `DataFrames` using `reduce`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table class=\"data-frame\"><thead><tr><th></th><th>x1</th><th>x2</th><th>x3</th><th>x4</th><th>x5</th></tr><tr><th></th><th>Float64</th><th>Float64</th><th>Float64</th><th>Float64</th><th>Float64</th></tr></thead><tbody><p>9 rows × 5 columns</p><tr><th>1</th><td>0.440897</td><td>0.953803</td><td>0.0135403</td><td>0.596537</td><td>0.548635</td></tr><tr><th>2</th><td>0.404673</td><td>0.0951856</td><td>0.303399</td><td>0.638935</td><td>0.262992</td></tr><tr><th>3</th><td>0.736787</td><td>0.519675</td><td>0.702557</td><td>0.872347</td><td>0.526443</td></tr><tr><th>4</th><td>0.440897</td><td>0.953803</td><td>0.0135403</td><td>0.596537</td><td>0.548635</td></tr><tr><th>5</th><td>0.404673</td><td>0.0951856</td><td>0.303399</td><td>0.638935</td><td>0.262992</td></tr><tr><th>6</th><td>0.736787</td><td>0.519675</td><td>0.702557</td><td>0.872347</td><td>0.526443</td></tr><tr><th>7</th><td>0.440897</td><td>0.953803</td><td>0.0135403</td><td>0.596537</td><td>0.548635</td></tr><tr><th>8</th><td>0.404673</td><td>0.0951856</td><td>0.303399</td><td>0.638935</td><td>0.262992</td></tr><tr><th>9</th><td>0.736787</td><td>0.519675</td><td>0.702557</td><td>0.872347</td><td>0.526443</td></tr></tbody></table>"
      ],
      "text/latex": [
       "\\begin{tabular}{r|ccccc}\n",
       "\t& x1 & x2 & x3 & x4 & x5\\\\\n",
       "\t\\hline\n",
       "\t& Float64 & Float64 & Float64 & Float64 & Float64\\\\\n",
       "\t\\hline\n",
       "\t1 & 0.440897 & 0.953803 & 0.0135403 & 0.596537 & 0.548635 \\\\\n",
       "\t2 & 0.404673 & 0.0951856 & 0.303399 & 0.638935 & 0.262992 \\\\\n",
       "\t3 & 0.736787 & 0.519675 & 0.702557 & 0.872347 & 0.526443 \\\\\n",
       "\t4 & 0.440897 & 0.953803 & 0.0135403 & 0.596537 & 0.548635 \\\\\n",
       "\t5 & 0.404673 & 0.0951856 & 0.303399 & 0.638935 & 0.262992 \\\\\n",
       "\t6 & 0.736787 & 0.519675 & 0.702557 & 0.872347 & 0.526443 \\\\\n",
       "\t7 & 0.440897 & 0.953803 & 0.0135403 & 0.596537 & 0.548635 \\\\\n",
       "\t8 & 0.404673 & 0.0951856 & 0.303399 & 0.638935 & 0.262992 \\\\\n",
       "\t9 & 0.736787 & 0.519675 & 0.702557 & 0.872347 & 0.526443 \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/plain": [
       "\u001b[1m9×5 DataFrame\u001b[0m\n",
       "\u001b[1m Row \u001b[0m│\u001b[1m x1       \u001b[0m\u001b[1m x2        \u001b[0m\u001b[1m x3        \u001b[0m\u001b[1m x4       \u001b[0m\u001b[1m x5       \u001b[0m\n",
       "\u001b[1m     \u001b[0m│\u001b[90m Float64  \u001b[0m\u001b[90m Float64   \u001b[0m\u001b[90m Float64   \u001b[0m\u001b[90m Float64  \u001b[0m\u001b[90m Float64  \u001b[0m\n",
       "─────┼────────────────────────────────────────────────────\n",
       "   1 │ 0.440897  0.953803   0.0135403  0.596537  0.548635\n",
       "   2 │ 0.404673  0.0951856  0.303399   0.638935  0.262992\n",
       "   3 │ 0.736787  0.519675   0.702557   0.872347  0.526443\n",
       "   4 │ 0.440897  0.953803   0.0135403  0.596537  0.548635\n",
       "   5 │ 0.404673  0.0951856  0.303399   0.638935  0.262992\n",
       "   6 │ 0.736787  0.519675   0.702557   0.872347  0.526443\n",
       "   7 │ 0.440897  0.953803   0.0135403  0.596537  0.548635\n",
       "   8 │ 0.404673  0.0951856  0.303399   0.638935  0.262992\n",
       "   9 │ 0.736787  0.519675   0.702557   0.872347  0.526443"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "reduce(vcat, [x, x, x])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "get `y` with other order of names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table class=\"data-frame\"><thead><tr><th></th><th>x5</th><th>x4</th><th>x3</th><th>x2</th><th>x1</th></tr><tr><th></th><th>Float64</th><th>Float64</th><th>Float64</th><th>Float64</th><th>Float64</th></tr></thead><tbody><p>3 rows × 5 columns</p><tr><th>1</th><td>0.548635</td><td>0.596537</td><td>0.0135403</td><td>0.953803</td><td>0.440897</td></tr><tr><th>2</th><td>0.262992</td><td>0.638935</td><td>0.303399</td><td>0.0951856</td><td>0.404673</td></tr><tr><th>3</th><td>0.526443</td><td>0.872347</td><td>0.702557</td><td>0.519675</td><td>0.736787</td></tr></tbody></table>"
      ],
      "text/latex": [
       "\\begin{tabular}{r|ccccc}\n",
       "\t& x5 & x4 & x3 & x2 & x1\\\\\n",
       "\t\\hline\n",
       "\t& Float64 & Float64 & Float64 & Float64 & Float64\\\\\n",
       "\t\\hline\n",
       "\t1 & 0.548635 & 0.596537 & 0.0135403 & 0.953803 & 0.440897 \\\\\n",
       "\t2 & 0.262992 & 0.638935 & 0.303399 & 0.0951856 & 0.404673 \\\\\n",
       "\t3 & 0.526443 & 0.872347 & 0.702557 & 0.519675 & 0.736787 \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/plain": [
       "\u001b[1m3×5 DataFrame\u001b[0m\n",
       "\u001b[1m Row \u001b[0m│\u001b[1m x5       \u001b[0m\u001b[1m x4       \u001b[0m\u001b[1m x3        \u001b[0m\u001b[1m x2        \u001b[0m\u001b[1m x1       \u001b[0m\n",
       "\u001b[1m     \u001b[0m│\u001b[90m Float64  \u001b[0m\u001b[90m Float64  \u001b[0m\u001b[90m Float64   \u001b[0m\u001b[90m Float64   \u001b[0m\u001b[90m Float64  \u001b[0m\n",
       "─────┼────────────────────────────────────────────────────\n",
       "   1 │ 0.548635  0.596537  0.0135403  0.953803   0.440897\n",
       "   2 │ 0.262992  0.638935  0.303399   0.0951856  0.404673\n",
       "   3 │ 0.526443  0.872347  0.702557   0.519675   0.736787"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "y = x[:, reverse(names(x))]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`vcat` is still possible as it does column name matching"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table class=\"data-frame\"><thead><tr><th></th><th>x1</th><th>x2</th><th>x3</th><th>x4</th><th>x5</th></tr><tr><th></th><th>Float64</th><th>Float64</th><th>Float64</th><th>Float64</th><th>Float64</th></tr></thead><tbody><p>6 rows × 5 columns</p><tr><th>1</th><td>0.440897</td><td>0.953803</td><td>0.0135403</td><td>0.596537</td><td>0.548635</td></tr><tr><th>2</th><td>0.404673</td><td>0.0951856</td><td>0.303399</td><td>0.638935</td><td>0.262992</td></tr><tr><th>3</th><td>0.736787</td><td>0.519675</td><td>0.702557</td><td>0.872347</td><td>0.526443</td></tr><tr><th>4</th><td>0.440897</td><td>0.953803</td><td>0.0135403</td><td>0.596537</td><td>0.548635</td></tr><tr><th>5</th><td>0.404673</td><td>0.0951856</td><td>0.303399</td><td>0.638935</td><td>0.262992</td></tr><tr><th>6</th><td>0.736787</td><td>0.519675</td><td>0.702557</td><td>0.872347</td><td>0.526443</td></tr></tbody></table>"
      ],
      "text/latex": [
       "\\begin{tabular}{r|ccccc}\n",
       "\t& x1 & x2 & x3 & x4 & x5\\\\\n",
       "\t\\hline\n",
       "\t& Float64 & Float64 & Float64 & Float64 & Float64\\\\\n",
       "\t\\hline\n",
       "\t1 & 0.440897 & 0.953803 & 0.0135403 & 0.596537 & 0.548635 \\\\\n",
       "\t2 & 0.404673 & 0.0951856 & 0.303399 & 0.638935 & 0.262992 \\\\\n",
       "\t3 & 0.736787 & 0.519675 & 0.702557 & 0.872347 & 0.526443 \\\\\n",
       "\t4 & 0.440897 & 0.953803 & 0.0135403 & 0.596537 & 0.548635 \\\\\n",
       "\t5 & 0.404673 & 0.0951856 & 0.303399 & 0.638935 & 0.262992 \\\\\n",
       "\t6 & 0.736787 & 0.519675 & 0.702557 & 0.872347 & 0.526443 \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/plain": [
       "\u001b[1m6×5 DataFrame\u001b[0m\n",
       "\u001b[1m Row \u001b[0m│\u001b[1m x1       \u001b[0m\u001b[1m x2        \u001b[0m\u001b[1m x3        \u001b[0m\u001b[1m x4       \u001b[0m\u001b[1m x5       \u001b[0m\n",
       "\u001b[1m     \u001b[0m│\u001b[90m Float64  \u001b[0m\u001b[90m Float64   \u001b[0m\u001b[90m Float64   \u001b[0m\u001b[90m Float64  \u001b[0m\u001b[90m Float64  \u001b[0m\n",
       "─────┼────────────────────────────────────────────────────\n",
       "   1 │ 0.440897  0.953803   0.0135403  0.596537  0.548635\n",
       "   2 │ 0.404673  0.0951856  0.303399   0.638935  0.262992\n",
       "   3 │ 0.736787  0.519675   0.702557   0.872347  0.526443\n",
       "   4 │ 0.440897  0.953803   0.0135403  0.596537  0.548635\n",
       "   5 │ 0.404673  0.0951856  0.303399   0.638935  0.262992\n",
       "   6 │ 0.736787  0.519675   0.702557   0.872347  0.526443"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "vcat(x, y)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "but column names must still match"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "ename": "LoadError",
     "evalue": "ArgumentError: column(s) x1 and x2 are missing from argument(s) 2",
     "output_type": "error",
     "traceback": [
      "ArgumentError: column(s) x1 and x2 are missing from argument(s) 2",
      "",
      "Stacktrace:",
      " [1] _vcat(::Array{DataFrame,1}; cols::Symbol) at D:\\AppData\\.julia\\packages\\DataFrames\\X0xNW\\src\\abstractdataframe\\abstractdataframe.jl:1597",
      " [2] #reduce#121 at D:\\AppData\\.julia\\packages\\DataFrames\\X0xNW\\src\\abstractdataframe\\abstractdataframe.jl:1554 [inlined]",
      " [3] #vcat#120 at D:\\AppData\\.julia\\packages\\DataFrames\\X0xNW\\src\\abstractdataframe\\abstractdataframe.jl:1547 [inlined]",
      " [4] vcat(::DataFrame, ::DataFrame) at D:\\AppData\\.julia\\packages\\DataFrames\\X0xNW\\src\\abstractdataframe\\abstractdataframe.jl:1547",
      " [5] top-level scope at In[34]:1",
      " [6] include_string(::Function, ::Module, ::String, ::String) at .\\loading.jl:1091"
     ]
    }
   ],
   "source": [
    "vcat(x, y[:, 1:3])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "unless you pass `:intersect`, `:union` or specific column names as keyword argument `cols`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table class=\"data-frame\"><thead><tr><th></th><th>x3</th><th>x4</th><th>x5</th></tr><tr><th></th><th>Float64</th><th>Float64</th><th>Float64</th></tr></thead><tbody><p>6 rows × 3 columns</p><tr><th>1</th><td>0.0135403</td><td>0.596537</td><td>0.548635</td></tr><tr><th>2</th><td>0.303399</td><td>0.638935</td><td>0.262992</td></tr><tr><th>3</th><td>0.702557</td><td>0.872347</td><td>0.526443</td></tr><tr><th>4</th><td>0.0135403</td><td>0.596537</td><td>0.548635</td></tr><tr><th>5</th><td>0.303399</td><td>0.638935</td><td>0.262992</td></tr><tr><th>6</th><td>0.702557</td><td>0.872347</td><td>0.526443</td></tr></tbody></table>"
      ],
      "text/latex": [
       "\\begin{tabular}{r|ccc}\n",
       "\t& x3 & x4 & x5\\\\\n",
       "\t\\hline\n",
       "\t& Float64 & Float64 & Float64\\\\\n",
       "\t\\hline\n",
       "\t1 & 0.0135403 & 0.596537 & 0.548635 \\\\\n",
       "\t2 & 0.303399 & 0.638935 & 0.262992 \\\\\n",
       "\t3 & 0.702557 & 0.872347 & 0.526443 \\\\\n",
       "\t4 & 0.0135403 & 0.596537 & 0.548635 \\\\\n",
       "\t5 & 0.303399 & 0.638935 & 0.262992 \\\\\n",
       "\t6 & 0.702557 & 0.872347 & 0.526443 \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/plain": [
       "\u001b[1m6×3 DataFrame\u001b[0m\n",
       "\u001b[1m Row \u001b[0m│\u001b[1m x3        \u001b[0m\u001b[1m x4       \u001b[0m\u001b[1m x5       \u001b[0m\n",
       "\u001b[1m     \u001b[0m│\u001b[90m Float64   \u001b[0m\u001b[90m Float64  \u001b[0m\u001b[90m Float64  \u001b[0m\n",
       "─────┼───────────────────────────────\n",
       "   1 │ 0.0135403  0.596537  0.548635\n",
       "   2 │ 0.303399   0.638935  0.262992\n",
       "   3 │ 0.702557   0.872347  0.526443\n",
       "   4 │ 0.0135403  0.596537  0.548635\n",
       "   5 │ 0.303399   0.638935  0.262992\n",
       "   6 │ 0.702557   0.872347  0.526443"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "vcat(x, y[:, 1:3], cols=:intersect)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table class=\"data-frame\"><thead><tr><th></th><th>x1</th><th>x2</th><th>x3</th><th>x4</th><th>x5</th></tr><tr><th></th><th>Float64?</th><th>Float64?</th><th>Float64</th><th>Float64</th><th>Float64</th></tr></thead><tbody><p>6 rows × 5 columns</p><tr><th>1</th><td>0.440897</td><td>0.953803</td><td>0.0135403</td><td>0.596537</td><td>0.548635</td></tr><tr><th>2</th><td>0.404673</td><td>0.0951856</td><td>0.303399</td><td>0.638935</td><td>0.262992</td></tr><tr><th>3</th><td>0.736787</td><td>0.519675</td><td>0.702557</td><td>0.872347</td><td>0.526443</td></tr><tr><th>4</th><td><em>missing</em></td><td><em>missing</em></td><td>0.0135403</td><td>0.596537</td><td>0.548635</td></tr><tr><th>5</th><td><em>missing</em></td><td><em>missing</em></td><td>0.303399</td><td>0.638935</td><td>0.262992</td></tr><tr><th>6</th><td><em>missing</em></td><td><em>missing</em></td><td>0.702557</td><td>0.872347</td><td>0.526443</td></tr></tbody></table>"
      ],
      "text/latex": [
       "\\begin{tabular}{r|ccccc}\n",
       "\t& x1 & x2 & x3 & x4 & x5\\\\\n",
       "\t\\hline\n",
       "\t& Float64? & Float64? & Float64 & Float64 & Float64\\\\\n",
       "\t\\hline\n",
       "\t1 & 0.440897 & 0.953803 & 0.0135403 & 0.596537 & 0.548635 \\\\\n",
       "\t2 & 0.404673 & 0.0951856 & 0.303399 & 0.638935 & 0.262992 \\\\\n",
       "\t3 & 0.736787 & 0.519675 & 0.702557 & 0.872347 & 0.526443 \\\\\n",
       "\t4 & \\emph{missing} & \\emph{missing} & 0.0135403 & 0.596537 & 0.548635 \\\\\n",
       "\t5 & \\emph{missing} & \\emph{missing} & 0.303399 & 0.638935 & 0.262992 \\\\\n",
       "\t6 & \\emph{missing} & \\emph{missing} & 0.702557 & 0.872347 & 0.526443 \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/plain": [
       "\u001b[1m6×5 DataFrame\u001b[0m\n",
       "\u001b[1m Row \u001b[0m│\u001b[1m x1             \u001b[0m\u001b[1m x2              \u001b[0m\u001b[1m x3        \u001b[0m\u001b[1m x4       \u001b[0m\u001b[1m x5       \u001b[0m\n",
       "\u001b[1m     \u001b[0m│\u001b[90m Float64?       \u001b[0m\u001b[90m Float64?        \u001b[0m\u001b[90m Float64   \u001b[0m\u001b[90m Float64  \u001b[0m\u001b[90m Float64  \u001b[0m\n",
       "─────┼────────────────────────────────────────────────────────────────\n",
       "   1 │       0.440897        0.953803   0.0135403  0.596537  0.548635\n",
       "   2 │       0.404673        0.0951856  0.303399   0.638935  0.262992\n",
       "   3 │       0.736787        0.519675   0.702557   0.872347  0.526443\n",
       "   4 │\u001b[90m missing        \u001b[0m\u001b[90m missing         \u001b[0m 0.0135403  0.596537  0.548635\n",
       "   5 │\u001b[90m missing        \u001b[0m\u001b[90m missing         \u001b[0m 0.303399   0.638935  0.262992\n",
       "   6 │\u001b[90m missing        \u001b[0m\u001b[90m missing         \u001b[0m 0.702557   0.872347  0.526443"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "vcat(x, y[:, 1:3], cols=:union)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table class=\"data-frame\"><thead><tr><th></th><th>x1</th><th>x5</th></tr><tr><th></th><th>Float64?</th><th>Float64</th></tr></thead><tbody><p>6 rows × 2 columns</p><tr><th>1</th><td>0.440897</td><td>0.548635</td></tr><tr><th>2</th><td>0.404673</td><td>0.262992</td></tr><tr><th>3</th><td>0.736787</td><td>0.526443</td></tr><tr><th>4</th><td><em>missing</em></td><td>0.548635</td></tr><tr><th>5</th><td><em>missing</em></td><td>0.262992</td></tr><tr><th>6</th><td><em>missing</em></td><td>0.526443</td></tr></tbody></table>"
      ],
      "text/latex": [
       "\\begin{tabular}{r|cc}\n",
       "\t& x1 & x5\\\\\n",
       "\t\\hline\n",
       "\t& Float64? & Float64\\\\\n",
       "\t\\hline\n",
       "\t1 & 0.440897 & 0.548635 \\\\\n",
       "\t2 & 0.404673 & 0.262992 \\\\\n",
       "\t3 & 0.736787 & 0.526443 \\\\\n",
       "\t4 & \\emph{missing} & 0.548635 \\\\\n",
       "\t5 & \\emph{missing} & 0.262992 \\\\\n",
       "\t6 & \\emph{missing} & 0.526443 \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/plain": [
       "\u001b[1m6×2 DataFrame\u001b[0m\n",
       "\u001b[1m Row \u001b[0m│\u001b[1m x1             \u001b[0m\u001b[1m x5       \u001b[0m\n",
       "\u001b[1m     \u001b[0m│\u001b[90m Float64?       \u001b[0m\u001b[90m Float64  \u001b[0m\n",
       "─────┼──────────────────────────\n",
       "   1 │       0.440897  0.548635\n",
       "   2 │       0.404673  0.262992\n",
       "   3 │       0.736787  0.526443\n",
       "   4 │\u001b[90m missing        \u001b[0m 0.548635\n",
       "   5 │\u001b[90m missing        \u001b[0m 0.262992\n",
       "   6 │\u001b[90m missing        \u001b[0m 0.526443"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "vcat(x, y[:, 1:3], cols=[:x1, :x5])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`append!` modifies `x` in place"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table class=\"data-frame\"><thead><tr><th></th><th>x1</th><th>x2</th><th>x3</th><th>x4</th><th>x5</th></tr><tr><th></th><th>Float64</th><th>Float64</th><th>Float64</th><th>Float64</th><th>Float64</th></tr></thead><tbody><p>6 rows × 5 columns</p><tr><th>1</th><td>0.440897</td><td>0.953803</td><td>0.0135403</td><td>0.596537</td><td>0.548635</td></tr><tr><th>2</th><td>0.404673</td><td>0.0951856</td><td>0.303399</td><td>0.638935</td><td>0.262992</td></tr><tr><th>3</th><td>0.736787</td><td>0.519675</td><td>0.702557</td><td>0.872347</td><td>0.526443</td></tr><tr><th>4</th><td>0.440897</td><td>0.953803</td><td>0.0135403</td><td>0.596537</td><td>0.548635</td></tr><tr><th>5</th><td>0.404673</td><td>0.0951856</td><td>0.303399</td><td>0.638935</td><td>0.262992</td></tr><tr><th>6</th><td>0.736787</td><td>0.519675</td><td>0.702557</td><td>0.872347</td><td>0.526443</td></tr></tbody></table>"
      ],
      "text/latex": [
       "\\begin{tabular}{r|ccccc}\n",
       "\t& x1 & x2 & x3 & x4 & x5\\\\\n",
       "\t\\hline\n",
       "\t& Float64 & Float64 & Float64 & Float64 & Float64\\\\\n",
       "\t\\hline\n",
       "\t1 & 0.440897 & 0.953803 & 0.0135403 & 0.596537 & 0.548635 \\\\\n",
       "\t2 & 0.404673 & 0.0951856 & 0.303399 & 0.638935 & 0.262992 \\\\\n",
       "\t3 & 0.736787 & 0.519675 & 0.702557 & 0.872347 & 0.526443 \\\\\n",
       "\t4 & 0.440897 & 0.953803 & 0.0135403 & 0.596537 & 0.548635 \\\\\n",
       "\t5 & 0.404673 & 0.0951856 & 0.303399 & 0.638935 & 0.262992 \\\\\n",
       "\t6 & 0.736787 & 0.519675 & 0.702557 & 0.872347 & 0.526443 \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/plain": [
       "\u001b[1m6×5 DataFrame\u001b[0m\n",
       "\u001b[1m Row \u001b[0m│\u001b[1m x1       \u001b[0m\u001b[1m x2        \u001b[0m\u001b[1m x3        \u001b[0m\u001b[1m x4       \u001b[0m\u001b[1m x5       \u001b[0m\n",
       "\u001b[1m     \u001b[0m│\u001b[90m Float64  \u001b[0m\u001b[90m Float64   \u001b[0m\u001b[90m Float64   \u001b[0m\u001b[90m Float64  \u001b[0m\u001b[90m Float64  \u001b[0m\n",
       "─────┼────────────────────────────────────────────────────\n",
       "   1 │ 0.440897  0.953803   0.0135403  0.596537  0.548635\n",
       "   2 │ 0.404673  0.0951856  0.303399   0.638935  0.262992\n",
       "   3 │ 0.736787  0.519675   0.702557   0.872347  0.526443\n",
       "   4 │ 0.440897  0.953803   0.0135403  0.596537  0.548635\n",
       "   5 │ 0.404673  0.0951856  0.303399   0.638935  0.262992\n",
       "   6 │ 0.736787  0.519675   0.702557   0.872347  0.526443"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "append!(x, x)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "here column names must match exactly unless `cols` keyword argument is passed"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table class=\"data-frame\"><thead><tr><th></th><th>x1</th><th>x2</th><th>x3</th><th>x4</th><th>x5</th></tr><tr><th></th><th>Float64</th><th>Float64</th><th>Float64</th><th>Float64</th><th>Float64</th></tr></thead><tbody><p>9 rows × 5 columns</p><tr><th>1</th><td>0.440897</td><td>0.953803</td><td>0.0135403</td><td>0.596537</td><td>0.548635</td></tr><tr><th>2</th><td>0.404673</td><td>0.0951856</td><td>0.303399</td><td>0.638935</td><td>0.262992</td></tr><tr><th>3</th><td>0.736787</td><td>0.519675</td><td>0.702557</td><td>0.872347</td><td>0.526443</td></tr><tr><th>4</th><td>0.440897</td><td>0.953803</td><td>0.0135403</td><td>0.596537</td><td>0.548635</td></tr><tr><th>5</th><td>0.404673</td><td>0.0951856</td><td>0.303399</td><td>0.638935</td><td>0.262992</td></tr><tr><th>6</th><td>0.736787</td><td>0.519675</td><td>0.702557</td><td>0.872347</td><td>0.526443</td></tr><tr><th>7</th><td>0.440897</td><td>0.953803</td><td>0.0135403</td><td>0.596537</td><td>0.548635</td></tr><tr><th>8</th><td>0.404673</td><td>0.0951856</td><td>0.303399</td><td>0.638935</td><td>0.262992</td></tr><tr><th>9</th><td>0.736787</td><td>0.519675</td><td>0.702557</td><td>0.872347</td><td>0.526443</td></tr></tbody></table>"
      ],
      "text/latex": [
       "\\begin{tabular}{r|ccccc}\n",
       "\t& x1 & x2 & x3 & x4 & x5\\\\\n",
       "\t\\hline\n",
       "\t& Float64 & Float64 & Float64 & Float64 & Float64\\\\\n",
       "\t\\hline\n",
       "\t1 & 0.440897 & 0.953803 & 0.0135403 & 0.596537 & 0.548635 \\\\\n",
       "\t2 & 0.404673 & 0.0951856 & 0.303399 & 0.638935 & 0.262992 \\\\\n",
       "\t3 & 0.736787 & 0.519675 & 0.702557 & 0.872347 & 0.526443 \\\\\n",
       "\t4 & 0.440897 & 0.953803 & 0.0135403 & 0.596537 & 0.548635 \\\\\n",
       "\t5 & 0.404673 & 0.0951856 & 0.303399 & 0.638935 & 0.262992 \\\\\n",
       "\t6 & 0.736787 & 0.519675 & 0.702557 & 0.872347 & 0.526443 \\\\\n",
       "\t7 & 0.440897 & 0.953803 & 0.0135403 & 0.596537 & 0.548635 \\\\\n",
       "\t8 & 0.404673 & 0.0951856 & 0.303399 & 0.638935 & 0.262992 \\\\\n",
       "\t9 & 0.736787 & 0.519675 & 0.702557 & 0.872347 & 0.526443 \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/plain": [
       "\u001b[1m9×5 DataFrame\u001b[0m\n",
       "\u001b[1m Row \u001b[0m│\u001b[1m x1       \u001b[0m\u001b[1m x2        \u001b[0m\u001b[1m x3        \u001b[0m\u001b[1m x4       \u001b[0m\u001b[1m x5       \u001b[0m\n",
       "\u001b[1m     \u001b[0m│\u001b[90m Float64  \u001b[0m\u001b[90m Float64   \u001b[0m\u001b[90m Float64   \u001b[0m\u001b[90m Float64  \u001b[0m\u001b[90m Float64  \u001b[0m\n",
       "─────┼────────────────────────────────────────────────────\n",
       "   1 │ 0.440897  0.953803   0.0135403  0.596537  0.548635\n",
       "   2 │ 0.404673  0.0951856  0.303399   0.638935  0.262992\n",
       "   3 │ 0.736787  0.519675   0.702557   0.872347  0.526443\n",
       "   4 │ 0.440897  0.953803   0.0135403  0.596537  0.548635\n",
       "   5 │ 0.404673  0.0951856  0.303399   0.638935  0.262992\n",
       "   6 │ 0.736787  0.519675   0.702557   0.872347  0.526443\n",
       "   7 │ 0.440897  0.953803   0.0135403  0.596537  0.548635\n",
       "   8 │ 0.404673  0.0951856  0.303399   0.638935  0.262992\n",
       "   9 │ 0.736787  0.519675   0.702557   0.872347  0.526443"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "append!(x, y)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "standard `repeat` function works on rows; also `inner` and `outer` keyword arguments are accepted"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table class=\"data-frame\"><thead><tr><th></th><th>x1</th><th>x2</th><th>x3</th><th>x4</th><th>x5</th></tr><tr><th></th><th>Float64</th><th>Float64</th><th>Float64</th><th>Float64</th><th>Float64</th></tr></thead><tbody><p>18 rows × 5 columns</p><tr><th>1</th><td>0.440897</td><td>0.953803</td><td>0.0135403</td><td>0.596537</td><td>0.548635</td></tr><tr><th>2</th><td>0.404673</td><td>0.0951856</td><td>0.303399</td><td>0.638935</td><td>0.262992</td></tr><tr><th>3</th><td>0.736787</td><td>0.519675</td><td>0.702557</td><td>0.872347</td><td>0.526443</td></tr><tr><th>4</th><td>0.440897</td><td>0.953803</td><td>0.0135403</td><td>0.596537</td><td>0.548635</td></tr><tr><th>5</th><td>0.404673</td><td>0.0951856</td><td>0.303399</td><td>0.638935</td><td>0.262992</td></tr><tr><th>6</th><td>0.736787</td><td>0.519675</td><td>0.702557</td><td>0.872347</td><td>0.526443</td></tr><tr><th>7</th><td>0.440897</td><td>0.953803</td><td>0.0135403</td><td>0.596537</td><td>0.548635</td></tr><tr><th>8</th><td>0.404673</td><td>0.0951856</td><td>0.303399</td><td>0.638935</td><td>0.262992</td></tr><tr><th>9</th><td>0.736787</td><td>0.519675</td><td>0.702557</td><td>0.872347</td><td>0.526443</td></tr><tr><th>10</th><td>0.440897</td><td>0.953803</td><td>0.0135403</td><td>0.596537</td><td>0.548635</td></tr><tr><th>11</th><td>0.404673</td><td>0.0951856</td><td>0.303399</td><td>0.638935</td><td>0.262992</td></tr><tr><th>12</th><td>0.736787</td><td>0.519675</td><td>0.702557</td><td>0.872347</td><td>0.526443</td></tr><tr><th>13</th><td>0.440897</td><td>0.953803</td><td>0.0135403</td><td>0.596537</td><td>0.548635</td></tr><tr><th>14</th><td>0.404673</td><td>0.0951856</td><td>0.303399</td><td>0.638935</td><td>0.262992</td></tr><tr><th>15</th><td>0.736787</td><td>0.519675</td><td>0.702557</td><td>0.872347</td><td>0.526443</td></tr><tr><th>16</th><td>0.440897</td><td>0.953803</td><td>0.0135403</td><td>0.596537</td><td>0.548635</td></tr><tr><th>17</th><td>0.404673</td><td>0.0951856</td><td>0.303399</td><td>0.638935</td><td>0.262992</td></tr><tr><th>18</th><td>0.736787</td><td>0.519675</td><td>0.702557</td><td>0.872347</td><td>0.526443</td></tr></tbody></table>"
      ],
      "text/latex": [
       "\\begin{tabular}{r|ccccc}\n",
       "\t& x1 & x2 & x3 & x4 & x5\\\\\n",
       "\t\\hline\n",
       "\t& Float64 & Float64 & Float64 & Float64 & Float64\\\\\n",
       "\t\\hline\n",
       "\t1 & 0.440897 & 0.953803 & 0.0135403 & 0.596537 & 0.548635 \\\\\n",
       "\t2 & 0.404673 & 0.0951856 & 0.303399 & 0.638935 & 0.262992 \\\\\n",
       "\t3 & 0.736787 & 0.519675 & 0.702557 & 0.872347 & 0.526443 \\\\\n",
       "\t4 & 0.440897 & 0.953803 & 0.0135403 & 0.596537 & 0.548635 \\\\\n",
       "\t5 & 0.404673 & 0.0951856 & 0.303399 & 0.638935 & 0.262992 \\\\\n",
       "\t6 & 0.736787 & 0.519675 & 0.702557 & 0.872347 & 0.526443 \\\\\n",
       "\t7 & 0.440897 & 0.953803 & 0.0135403 & 0.596537 & 0.548635 \\\\\n",
       "\t8 & 0.404673 & 0.0951856 & 0.303399 & 0.638935 & 0.262992 \\\\\n",
       "\t9 & 0.736787 & 0.519675 & 0.702557 & 0.872347 & 0.526443 \\\\\n",
       "\t10 & 0.440897 & 0.953803 & 0.0135403 & 0.596537 & 0.548635 \\\\\n",
       "\t11 & 0.404673 & 0.0951856 & 0.303399 & 0.638935 & 0.262992 \\\\\n",
       "\t12 & 0.736787 & 0.519675 & 0.702557 & 0.872347 & 0.526443 \\\\\n",
       "\t13 & 0.440897 & 0.953803 & 0.0135403 & 0.596537 & 0.548635 \\\\\n",
       "\t14 & 0.404673 & 0.0951856 & 0.303399 & 0.638935 & 0.262992 \\\\\n",
       "\t15 & 0.736787 & 0.519675 & 0.702557 & 0.872347 & 0.526443 \\\\\n",
       "\t16 & 0.440897 & 0.953803 & 0.0135403 & 0.596537 & 0.548635 \\\\\n",
       "\t17 & 0.404673 & 0.0951856 & 0.303399 & 0.638935 & 0.262992 \\\\\n",
       "\t18 & 0.736787 & 0.519675 & 0.702557 & 0.872347 & 0.526443 \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/plain": [
       "\u001b[1m18×5 DataFrame\u001b[0m\n",
       "\u001b[1m Row \u001b[0m│\u001b[1m x1       \u001b[0m\u001b[1m x2        \u001b[0m\u001b[1m x3        \u001b[0m\u001b[1m x4       \u001b[0m\u001b[1m x5       \u001b[0m\n",
       "\u001b[1m     \u001b[0m│\u001b[90m Float64  \u001b[0m\u001b[90m Float64   \u001b[0m\u001b[90m Float64   \u001b[0m\u001b[90m Float64  \u001b[0m\u001b[90m Float64  \u001b[0m\n",
       "─────┼────────────────────────────────────────────────────\n",
       "   1 │ 0.440897  0.953803   0.0135403  0.596537  0.548635\n",
       "   2 │ 0.404673  0.0951856  0.303399   0.638935  0.262992\n",
       "   3 │ 0.736787  0.519675   0.702557   0.872347  0.526443\n",
       "   4 │ 0.440897  0.953803   0.0135403  0.596537  0.548635\n",
       "   5 │ 0.404673  0.0951856  0.303399   0.638935  0.262992\n",
       "   6 │ 0.736787  0.519675   0.702557   0.872347  0.526443\n",
       "   7 │ 0.440897  0.953803   0.0135403  0.596537  0.548635\n",
       "   8 │ 0.404673  0.0951856  0.303399   0.638935  0.262992\n",
       "   9 │ 0.736787  0.519675   0.702557   0.872347  0.526443\n",
       "  10 │ 0.440897  0.953803   0.0135403  0.596537  0.548635\n",
       "  11 │ 0.404673  0.0951856  0.303399   0.638935  0.262992\n",
       "  12 │ 0.736787  0.519675   0.702557   0.872347  0.526443\n",
       "  13 │ 0.440897  0.953803   0.0135403  0.596537  0.548635\n",
       "  14 │ 0.404673  0.0951856  0.303399   0.638935  0.262992\n",
       "  15 │ 0.736787  0.519675   0.702557   0.872347  0.526443\n",
       "  16 │ 0.440897  0.953803   0.0135403  0.596537  0.548635\n",
       "  17 │ 0.404673  0.0951856  0.303399   0.638935  0.262992\n",
       "  18 │ 0.736787  0.519675   0.702557   0.872347  0.526443"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "repeat(x, 2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`push!` adds one row to `x` at the end; one must pass a correct number of values unless `cols` keyword argument is passed"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table class=\"data-frame\"><thead><tr><th></th><th>x1</th><th>x2</th><th>x3</th><th>x4</th><th>x5</th></tr><tr><th></th><th>Float64</th><th>Float64</th><th>Float64</th><th>Float64</th><th>Float64</th></tr></thead><tbody><p>10 rows × 5 columns</p><tr><th>1</th><td>0.440897</td><td>0.953803</td><td>0.0135403</td><td>0.596537</td><td>0.548635</td></tr><tr><th>2</th><td>0.404673</td><td>0.0951856</td><td>0.303399</td><td>0.638935</td><td>0.262992</td></tr><tr><th>3</th><td>0.736787</td><td>0.519675</td><td>0.702557</td><td>0.872347</td><td>0.526443</td></tr><tr><th>4</th><td>0.440897</td><td>0.953803</td><td>0.0135403</td><td>0.596537</td><td>0.548635</td></tr><tr><th>5</th><td>0.404673</td><td>0.0951856</td><td>0.303399</td><td>0.638935</td><td>0.262992</td></tr><tr><th>6</th><td>0.736787</td><td>0.519675</td><td>0.702557</td><td>0.872347</td><td>0.526443</td></tr><tr><th>7</th><td>0.440897</td><td>0.953803</td><td>0.0135403</td><td>0.596537</td><td>0.548635</td></tr><tr><th>8</th><td>0.404673</td><td>0.0951856</td><td>0.303399</td><td>0.638935</td><td>0.262992</td></tr><tr><th>9</th><td>0.736787</td><td>0.519675</td><td>0.702557</td><td>0.872347</td><td>0.526443</td></tr><tr><th>10</th><td>1.0</td><td>2.0</td><td>3.0</td><td>4.0</td><td>5.0</td></tr></tbody></table>"
      ],
      "text/latex": [
       "\\begin{tabular}{r|ccccc}\n",
       "\t& x1 & x2 & x3 & x4 & x5\\\\\n",
       "\t\\hline\n",
       "\t& Float64 & Float64 & Float64 & Float64 & Float64\\\\\n",
       "\t\\hline\n",
       "\t1 & 0.440897 & 0.953803 & 0.0135403 & 0.596537 & 0.548635 \\\\\n",
       "\t2 & 0.404673 & 0.0951856 & 0.303399 & 0.638935 & 0.262992 \\\\\n",
       "\t3 & 0.736787 & 0.519675 & 0.702557 & 0.872347 & 0.526443 \\\\\n",
       "\t4 & 0.440897 & 0.953803 & 0.0135403 & 0.596537 & 0.548635 \\\\\n",
       "\t5 & 0.404673 & 0.0951856 & 0.303399 & 0.638935 & 0.262992 \\\\\n",
       "\t6 & 0.736787 & 0.519675 & 0.702557 & 0.872347 & 0.526443 \\\\\n",
       "\t7 & 0.440897 & 0.953803 & 0.0135403 & 0.596537 & 0.548635 \\\\\n",
       "\t8 & 0.404673 & 0.0951856 & 0.303399 & 0.638935 & 0.262992 \\\\\n",
       "\t9 & 0.736787 & 0.519675 & 0.702557 & 0.872347 & 0.526443 \\\\\n",
       "\t10 & 1.0 & 2.0 & 3.0 & 4.0 & 5.0 \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/plain": [
       "\u001b[1m10×5 DataFrame\u001b[0m\n",
       "\u001b[1m Row \u001b[0m│\u001b[1m x1       \u001b[0m\u001b[1m x2        \u001b[0m\u001b[1m x3        \u001b[0m\u001b[1m x4       \u001b[0m\u001b[1m x5       \u001b[0m\n",
       "\u001b[1m     \u001b[0m│\u001b[90m Float64  \u001b[0m\u001b[90m Float64   \u001b[0m\u001b[90m Float64   \u001b[0m\u001b[90m Float64  \u001b[0m\u001b[90m Float64  \u001b[0m\n",
       "─────┼────────────────────────────────────────────────────\n",
       "   1 │ 0.440897  0.953803   0.0135403  0.596537  0.548635\n",
       "   2 │ 0.404673  0.0951856  0.303399   0.638935  0.262992\n",
       "   3 │ 0.736787  0.519675   0.702557   0.872347  0.526443\n",
       "   4 │ 0.440897  0.953803   0.0135403  0.596537  0.548635\n",
       "   5 │ 0.404673  0.0951856  0.303399   0.638935  0.262992\n",
       "   6 │ 0.736787  0.519675   0.702557   0.872347  0.526443\n",
       "   7 │ 0.440897  0.953803   0.0135403  0.596537  0.548635\n",
       "   8 │ 0.404673  0.0951856  0.303399   0.638935  0.262992\n",
       "   9 │ 0.736787  0.519675   0.702557   0.872347  0.526443\n",
       "  10 │ 1.0       2.0        3.0        4.0       5.0"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "push!(x, 1:5)\n",
    "x"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "also works with dictionaries"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table class=\"data-frame\"><thead><tr><th></th><th>x1</th><th>x2</th><th>x3</th><th>x4</th><th>x5</th></tr><tr><th></th><th>Float64</th><th>Float64</th><th>Float64</th><th>Float64</th><th>Float64</th></tr></thead><tbody><p>11 rows × 5 columns</p><tr><th>1</th><td>0.440897</td><td>0.953803</td><td>0.0135403</td><td>0.596537</td><td>0.548635</td></tr><tr><th>2</th><td>0.404673</td><td>0.0951856</td><td>0.303399</td><td>0.638935</td><td>0.262992</td></tr><tr><th>3</th><td>0.736787</td><td>0.519675</td><td>0.702557</td><td>0.872347</td><td>0.526443</td></tr><tr><th>4</th><td>0.440897</td><td>0.953803</td><td>0.0135403</td><td>0.596537</td><td>0.548635</td></tr><tr><th>5</th><td>0.404673</td><td>0.0951856</td><td>0.303399</td><td>0.638935</td><td>0.262992</td></tr><tr><th>6</th><td>0.736787</td><td>0.519675</td><td>0.702557</td><td>0.872347</td><td>0.526443</td></tr><tr><th>7</th><td>0.440897</td><td>0.953803</td><td>0.0135403</td><td>0.596537</td><td>0.548635</td></tr><tr><th>8</th><td>0.404673</td><td>0.0951856</td><td>0.303399</td><td>0.638935</td><td>0.262992</td></tr><tr><th>9</th><td>0.736787</td><td>0.519675</td><td>0.702557</td><td>0.872347</td><td>0.526443</td></tr><tr><th>10</th><td>1.0</td><td>2.0</td><td>3.0</td><td>4.0</td><td>5.0</td></tr><tr><th>11</th><td>11.0</td><td>12.0</td><td>13.0</td><td>14.0</td><td>15.0</td></tr></tbody></table>"
      ],
      "text/latex": [
       "\\begin{tabular}{r|ccccc}\n",
       "\t& x1 & x2 & x3 & x4 & x5\\\\\n",
       "\t\\hline\n",
       "\t& Float64 & Float64 & Float64 & Float64 & Float64\\\\\n",
       "\t\\hline\n",
       "\t1 & 0.440897 & 0.953803 & 0.0135403 & 0.596537 & 0.548635 \\\\\n",
       "\t2 & 0.404673 & 0.0951856 & 0.303399 & 0.638935 & 0.262992 \\\\\n",
       "\t3 & 0.736787 & 0.519675 & 0.702557 & 0.872347 & 0.526443 \\\\\n",
       "\t4 & 0.440897 & 0.953803 & 0.0135403 & 0.596537 & 0.548635 \\\\\n",
       "\t5 & 0.404673 & 0.0951856 & 0.303399 & 0.638935 & 0.262992 \\\\\n",
       "\t6 & 0.736787 & 0.519675 & 0.702557 & 0.872347 & 0.526443 \\\\\n",
       "\t7 & 0.440897 & 0.953803 & 0.0135403 & 0.596537 & 0.548635 \\\\\n",
       "\t8 & 0.404673 & 0.0951856 & 0.303399 & 0.638935 & 0.262992 \\\\\n",
       "\t9 & 0.736787 & 0.519675 & 0.702557 & 0.872347 & 0.526443 \\\\\n",
       "\t10 & 1.0 & 2.0 & 3.0 & 4.0 & 5.0 \\\\\n",
       "\t11 & 11.0 & 12.0 & 13.0 & 14.0 & 15.0 \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/plain": [
       "\u001b[1m11×5 DataFrame\u001b[0m\n",
       "\u001b[1m Row \u001b[0m│\u001b[1m x1        \u001b[0m\u001b[1m x2         \u001b[0m\u001b[1m x3         \u001b[0m\u001b[1m x4        \u001b[0m\u001b[1m x5        \u001b[0m\n",
       "\u001b[1m     \u001b[0m│\u001b[90m Float64   \u001b[0m\u001b[90m Float64    \u001b[0m\u001b[90m Float64    \u001b[0m\u001b[90m Float64   \u001b[0m\u001b[90m Float64   \u001b[0m\n",
       "─────┼─────────────────────────────────────────────────────────\n",
       "   1 │  0.440897   0.953803    0.0135403   0.596537   0.548635\n",
       "   2 │  0.404673   0.0951856   0.303399    0.638935   0.262992\n",
       "   3 │  0.736787   0.519675    0.702557    0.872347   0.526443\n",
       "   4 │  0.440897   0.953803    0.0135403   0.596537   0.548635\n",
       "   5 │  0.404673   0.0951856   0.303399    0.638935   0.262992\n",
       "   6 │  0.736787   0.519675    0.702557    0.872347   0.526443\n",
       "   7 │  0.440897   0.953803    0.0135403   0.596537   0.548635\n",
       "   8 │  0.404673   0.0951856   0.303399    0.638935   0.262992\n",
       "   9 │  0.736787   0.519675    0.702557    0.872347   0.526443\n",
       "  10 │  1.0        2.0         3.0         4.0        5.0\n",
       "  11 │ 11.0       12.0        13.0        14.0       15.0"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "push!(x, Dict(:x1=> 11, :x2=> 12, :x3=> 13, :x4=> 14, :x5=> 15))\n",
    "x"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "and `NamedTuples` via name matching"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table class=\"data-frame\"><thead><tr><th></th><th>x1</th><th>x2</th><th>x3</th><th>x4</th><th>x5</th></tr><tr><th></th><th>Float64</th><th>Float64</th><th>Float64</th><th>Float64</th><th>Float64</th></tr></thead><tbody><p>12 rows × 5 columns</p><tr><th>1</th><td>0.440897</td><td>0.953803</td><td>0.0135403</td><td>0.596537</td><td>0.548635</td></tr><tr><th>2</th><td>0.404673</td><td>0.0951856</td><td>0.303399</td><td>0.638935</td><td>0.262992</td></tr><tr><th>3</th><td>0.736787</td><td>0.519675</td><td>0.702557</td><td>0.872347</td><td>0.526443</td></tr><tr><th>4</th><td>0.440897</td><td>0.953803</td><td>0.0135403</td><td>0.596537</td><td>0.548635</td></tr><tr><th>5</th><td>0.404673</td><td>0.0951856</td><td>0.303399</td><td>0.638935</td><td>0.262992</td></tr><tr><th>6</th><td>0.736787</td><td>0.519675</td><td>0.702557</td><td>0.872347</td><td>0.526443</td></tr><tr><th>7</th><td>0.440897</td><td>0.953803</td><td>0.0135403</td><td>0.596537</td><td>0.548635</td></tr><tr><th>8</th><td>0.404673</td><td>0.0951856</td><td>0.303399</td><td>0.638935</td><td>0.262992</td></tr><tr><th>9</th><td>0.736787</td><td>0.519675</td><td>0.702557</td><td>0.872347</td><td>0.526443</td></tr><tr><th>10</th><td>1.0</td><td>2.0</td><td>3.0</td><td>4.0</td><td>5.0</td></tr><tr><th>11</th><td>11.0</td><td>12.0</td><td>13.0</td><td>14.0</td><td>15.0</td></tr><tr><th>12</th><td>1.0</td><td>2.0</td><td>3.0</td><td>4.0</td><td>5.0</td></tr></tbody></table>"
      ],
      "text/latex": [
       "\\begin{tabular}{r|ccccc}\n",
       "\t& x1 & x2 & x3 & x4 & x5\\\\\n",
       "\t\\hline\n",
       "\t& Float64 & Float64 & Float64 & Float64 & Float64\\\\\n",
       "\t\\hline\n",
       "\t1 & 0.440897 & 0.953803 & 0.0135403 & 0.596537 & 0.548635 \\\\\n",
       "\t2 & 0.404673 & 0.0951856 & 0.303399 & 0.638935 & 0.262992 \\\\\n",
       "\t3 & 0.736787 & 0.519675 & 0.702557 & 0.872347 & 0.526443 \\\\\n",
       "\t4 & 0.440897 & 0.953803 & 0.0135403 & 0.596537 & 0.548635 \\\\\n",
       "\t5 & 0.404673 & 0.0951856 & 0.303399 & 0.638935 & 0.262992 \\\\\n",
       "\t6 & 0.736787 & 0.519675 & 0.702557 & 0.872347 & 0.526443 \\\\\n",
       "\t7 & 0.440897 & 0.953803 & 0.0135403 & 0.596537 & 0.548635 \\\\\n",
       "\t8 & 0.404673 & 0.0951856 & 0.303399 & 0.638935 & 0.262992 \\\\\n",
       "\t9 & 0.736787 & 0.519675 & 0.702557 & 0.872347 & 0.526443 \\\\\n",
       "\t10 & 1.0 & 2.0 & 3.0 & 4.0 & 5.0 \\\\\n",
       "\t11 & 11.0 & 12.0 & 13.0 & 14.0 & 15.0 \\\\\n",
       "\t12 & 1.0 & 2.0 & 3.0 & 4.0 & 5.0 \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/plain": [
       "\u001b[1m12×5 DataFrame\u001b[0m\n",
       "\u001b[1m Row \u001b[0m│\u001b[1m x1        \u001b[0m\u001b[1m x2         \u001b[0m\u001b[1m x3         \u001b[0m\u001b[1m x4        \u001b[0m\u001b[1m x5        \u001b[0m\n",
       "\u001b[1m     \u001b[0m│\u001b[90m Float64   \u001b[0m\u001b[90m Float64    \u001b[0m\u001b[90m Float64    \u001b[0m\u001b[90m Float64   \u001b[0m\u001b[90m Float64   \u001b[0m\n",
       "─────┼─────────────────────────────────────────────────────────\n",
       "   1 │  0.440897   0.953803    0.0135403   0.596537   0.548635\n",
       "   2 │  0.404673   0.0951856   0.303399    0.638935   0.262992\n",
       "   3 │  0.736787   0.519675    0.702557    0.872347   0.526443\n",
       "   4 │  0.440897   0.953803    0.0135403   0.596537   0.548635\n",
       "   5 │  0.404673   0.0951856   0.303399    0.638935   0.262992\n",
       "   6 │  0.736787   0.519675    0.702557    0.872347   0.526443\n",
       "   7 │  0.440897   0.953803    0.0135403   0.596537   0.548635\n",
       "   8 │  0.404673   0.0951856   0.303399    0.638935   0.262992\n",
       "   9 │  0.736787   0.519675    0.702557    0.872347   0.526443\n",
       "  10 │  1.0        2.0         3.0         4.0        5.0\n",
       "  11 │ 11.0       12.0        13.0        14.0       15.0\n",
       "  12 │  1.0        2.0         3.0         4.0        5.0"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "push!(x, (x2=2, x1=1, x4=4, x3=3, x5=5))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "and `DataFrameRow` also via name matching"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table class=\"data-frame\"><thead><tr><th></th><th>x1</th><th>x2</th><th>x3</th><th>x4</th><th>x5</th></tr><tr><th></th><th>Float64</th><th>Float64</th><th>Float64</th><th>Float64</th><th>Float64</th></tr></thead><tbody><p>13 rows × 5 columns</p><tr><th>1</th><td>0.440897</td><td>0.953803</td><td>0.0135403</td><td>0.596537</td><td>0.548635</td></tr><tr><th>2</th><td>0.404673</td><td>0.0951856</td><td>0.303399</td><td>0.638935</td><td>0.262992</td></tr><tr><th>3</th><td>0.736787</td><td>0.519675</td><td>0.702557</td><td>0.872347</td><td>0.526443</td></tr><tr><th>4</th><td>0.440897</td><td>0.953803</td><td>0.0135403</td><td>0.596537</td><td>0.548635</td></tr><tr><th>5</th><td>0.404673</td><td>0.0951856</td><td>0.303399</td><td>0.638935</td><td>0.262992</td></tr><tr><th>6</th><td>0.736787</td><td>0.519675</td><td>0.702557</td><td>0.872347</td><td>0.526443</td></tr><tr><th>7</th><td>0.440897</td><td>0.953803</td><td>0.0135403</td><td>0.596537</td><td>0.548635</td></tr><tr><th>8</th><td>0.404673</td><td>0.0951856</td><td>0.303399</td><td>0.638935</td><td>0.262992</td></tr><tr><th>9</th><td>0.736787</td><td>0.519675</td><td>0.702557</td><td>0.872347</td><td>0.526443</td></tr><tr><th>10</th><td>1.0</td><td>2.0</td><td>3.0</td><td>4.0</td><td>5.0</td></tr><tr><th>11</th><td>11.0</td><td>12.0</td><td>13.0</td><td>14.0</td><td>15.0</td></tr><tr><th>12</th><td>1.0</td><td>2.0</td><td>3.0</td><td>4.0</td><td>5.0</td></tr><tr><th>13</th><td>0.440897</td><td>0.953803</td><td>0.0135403</td><td>0.596537</td><td>0.548635</td></tr></tbody></table>"
      ],
      "text/latex": [
       "\\begin{tabular}{r|ccccc}\n",
       "\t& x1 & x2 & x3 & x4 & x5\\\\\n",
       "\t\\hline\n",
       "\t& Float64 & Float64 & Float64 & Float64 & Float64\\\\\n",
       "\t\\hline\n",
       "\t1 & 0.440897 & 0.953803 & 0.0135403 & 0.596537 & 0.548635 \\\\\n",
       "\t2 & 0.404673 & 0.0951856 & 0.303399 & 0.638935 & 0.262992 \\\\\n",
       "\t3 & 0.736787 & 0.519675 & 0.702557 & 0.872347 & 0.526443 \\\\\n",
       "\t4 & 0.440897 & 0.953803 & 0.0135403 & 0.596537 & 0.548635 \\\\\n",
       "\t5 & 0.404673 & 0.0951856 & 0.303399 & 0.638935 & 0.262992 \\\\\n",
       "\t6 & 0.736787 & 0.519675 & 0.702557 & 0.872347 & 0.526443 \\\\\n",
       "\t7 & 0.440897 & 0.953803 & 0.0135403 & 0.596537 & 0.548635 \\\\\n",
       "\t8 & 0.404673 & 0.0951856 & 0.303399 & 0.638935 & 0.262992 \\\\\n",
       "\t9 & 0.736787 & 0.519675 & 0.702557 & 0.872347 & 0.526443 \\\\\n",
       "\t10 & 1.0 & 2.0 & 3.0 & 4.0 & 5.0 \\\\\n",
       "\t11 & 11.0 & 12.0 & 13.0 & 14.0 & 15.0 \\\\\n",
       "\t12 & 1.0 & 2.0 & 3.0 & 4.0 & 5.0 \\\\\n",
       "\t13 & 0.440897 & 0.953803 & 0.0135403 & 0.596537 & 0.548635 \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/plain": [
       "\u001b[1m13×5 DataFrame\u001b[0m\n",
       "\u001b[1m Row \u001b[0m│\u001b[1m x1        \u001b[0m\u001b[1m x2         \u001b[0m\u001b[1m x3         \u001b[0m\u001b[1m x4        \u001b[0m\u001b[1m x5        \u001b[0m\n",
       "\u001b[1m     \u001b[0m│\u001b[90m Float64   \u001b[0m\u001b[90m Float64    \u001b[0m\u001b[90m Float64    \u001b[0m\u001b[90m Float64   \u001b[0m\u001b[90m Float64   \u001b[0m\n",
       "─────┼─────────────────────────────────────────────────────────\n",
       "   1 │  0.440897   0.953803    0.0135403   0.596537   0.548635\n",
       "   2 │  0.404673   0.0951856   0.303399    0.638935   0.262992\n",
       "   3 │  0.736787   0.519675    0.702557    0.872347   0.526443\n",
       "   4 │  0.440897   0.953803    0.0135403   0.596537   0.548635\n",
       "   5 │  0.404673   0.0951856   0.303399    0.638935   0.262992\n",
       "   6 │  0.736787   0.519675    0.702557    0.872347   0.526443\n",
       "   7 │  0.440897   0.953803    0.0135403   0.596537   0.548635\n",
       "   8 │  0.404673   0.0951856   0.303399    0.638935   0.262992\n",
       "   9 │  0.736787   0.519675    0.702557    0.872347   0.526443\n",
       "  10 │  1.0        2.0         3.0         4.0        5.0\n",
       "  11 │ 11.0       12.0        13.0        14.0       15.0\n",
       "  12 │  1.0        2.0         3.0         4.0        5.0\n",
       "  13 │  0.440897   0.953803    0.0135403   0.596537   0.548635"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "push!(x, x[1, :])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Please consult the documentation of `push!`, `append!` and `vcat` for allowed values of `cols` keyword argument.\n",
    "This keyword argument governs the way these functions perform column matching of passed arguments. Also `append!` and `push!` support a `promote` keyword argument that decides if column type promotion is allowed."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Let us here just give a quick example of how heterogeneous data can be stored in the data frame using these functionalities:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3-element Array{NamedTuple,1}:\n",
       " (a = 1, b = 2)\n",
       " (a = missing, b = 10, c = 20)\n",
       " (b = \"s\", c = 1, d = 1)"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "source = [(a=1, b=2), (a=missing, b=10, c=20), (b=\"s\", c=1, d=1)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table class=\"data-frame\"><thead><tr><th></th></tr><tr><th></th></tr></thead><tbody><p>0 rows × 0 columns</p></tbody></table>"
      ],
      "text/latex": [
       "\\begin{tabular}{r|}\n",
       "\t& \\\\\n",
       "\t\\hline\n",
       "\t& \\\\\n",
       "\t\\hline\n",
       "\\end{tabular}\n"
      ],
      "text/plain": [
       "\u001b[1m0×0 DataFrame\u001b[0m"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = DataFrame()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [],
   "source": [
    "for row in source\n",
    "    push!(df, row, cols=:union) # if cols is :union then promote is true by default\n",
    "end"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table class=\"data-frame\"><thead><tr><th></th><th>a</th><th>b</th><th>c</th><th>d</th></tr><tr><th></th><th>Int64?</th><th>Any</th><th>Int64?</th><th>Int64?</th></tr></thead><tbody><p>3 rows × 4 columns</p><tr><th>1</th><td>1</td><td>2</td><td><em>missing</em></td><td><em>missing</em></td></tr><tr><th>2</th><td><em>missing</em></td><td>10</td><td>20</td><td><em>missing</em></td></tr><tr><th>3</th><td><em>missing</em></td><td>s</td><td>1</td><td>1</td></tr></tbody></table>"
      ],
      "text/latex": [
       "\\begin{tabular}{r|cccc}\n",
       "\t& a & b & c & d\\\\\n",
       "\t\\hline\n",
       "\t& Int64? & Any & Int64? & Int64?\\\\\n",
       "\t\\hline\n",
       "\t1 & 1 & 2 & \\emph{missing} & \\emph{missing} \\\\\n",
       "\t2 & \\emph{missing} & 10 & 20 & \\emph{missing} \\\\\n",
       "\t3 & \\emph{missing} & s & 1 & 1 \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/plain": [
       "\u001b[1m3×4 DataFrame\u001b[0m\n",
       "\u001b[1m Row \u001b[0m│\u001b[1m a       \u001b[0m\u001b[1m b   \u001b[0m\u001b[1m c       \u001b[0m\u001b[1m d       \u001b[0m\n",
       "\u001b[1m     \u001b[0m│\u001b[90m Int64?  \u001b[0m\u001b[90m Any \u001b[0m\u001b[90m Int64?  \u001b[0m\u001b[90m Int64?  \u001b[0m\n",
       "─────┼────────────────────────────────\n",
       "   1 │       1  2   \u001b[90m missing \u001b[0m\u001b[90m missing \u001b[0m\n",
       "   2 │\u001b[90m missing \u001b[0m 10        20 \u001b[90m missing \u001b[0m\n",
       "   3 │\u001b[90m missing \u001b[0m s          1        1"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "and we see that `push!` dynamically added columns as needed and updated their element types"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Subsetting/removing rows"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table class=\"data-frame\"><thead><tr><th></th><th>id</th><th>val</th></tr><tr><th></th><th>Int64</th><th>Char</th></tr></thead><tbody><p>10 rows × 2 columns</p><tr><th>1</th><td>1</td><td>a</td></tr><tr><th>2</th><td>2</td><td>b</td></tr><tr><th>3</th><td>3</td><td>c</td></tr><tr><th>4</th><td>4</td><td>d</td></tr><tr><th>5</th><td>5</td><td>e</td></tr><tr><th>6</th><td>6</td><td>f</td></tr><tr><th>7</th><td>7</td><td>g</td></tr><tr><th>8</th><td>8</td><td>h</td></tr><tr><th>9</th><td>9</td><td>i</td></tr><tr><th>10</th><td>10</td><td>j</td></tr></tbody></table>"
      ],
      "text/latex": [
       "\\begin{tabular}{r|cc}\n",
       "\t& id & val\\\\\n",
       "\t\\hline\n",
       "\t& Int64 & Char\\\\\n",
       "\t\\hline\n",
       "\t1 & 1 & a \\\\\n",
       "\t2 & 2 & b \\\\\n",
       "\t3 & 3 & c \\\\\n",
       "\t4 & 4 & d \\\\\n",
       "\t5 & 5 & e \\\\\n",
       "\t6 & 6 & f \\\\\n",
       "\t7 & 7 & g \\\\\n",
       "\t8 & 8 & h \\\\\n",
       "\t9 & 9 & i \\\\\n",
       "\t10 & 10 & j \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/plain": [
       "\u001b[1m10×2 DataFrame\u001b[0m\n",
       "\u001b[1m Row \u001b[0m│\u001b[1m id    \u001b[0m\u001b[1m val  \u001b[0m\n",
       "\u001b[1m     \u001b[0m│\u001b[90m Int64 \u001b[0m\u001b[90m Char \u001b[0m\n",
       "─────┼─────────────\n",
       "   1 │     1  a\n",
       "   2 │     2  b\n",
       "   3 │     3  c\n",
       "   4 │     4  d\n",
       "   5 │     5  e\n",
       "   6 │     6  f\n",
       "   7 │     7  g\n",
       "   8 │     8  h\n",
       "   9 │     9  i\n",
       "  10 │    10  j"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x = DataFrame(id=1:10, val='a':'j')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "by using indexing"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table class=\"data-frame\"><thead><tr><th></th><th>id</th><th>val</th></tr><tr><th></th><th>Int64</th><th>Char</th></tr></thead><tbody><p>2 rows × 2 columns</p><tr><th>1</th><td>1</td><td>a</td></tr><tr><th>2</th><td>2</td><td>b</td></tr></tbody></table>"
      ],
      "text/latex": [
       "\\begin{tabular}{r|cc}\n",
       "\t& id & val\\\\\n",
       "\t\\hline\n",
       "\t& Int64 & Char\\\\\n",
       "\t\\hline\n",
       "\t1 & 1 & a \\\\\n",
       "\t2 & 2 & b \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/plain": [
       "\u001b[1m2×2 DataFrame\u001b[0m\n",
       "\u001b[1m Row \u001b[0m│\u001b[1m id    \u001b[0m\u001b[1m val  \u001b[0m\n",
       "\u001b[1m     \u001b[0m│\u001b[90m Int64 \u001b[0m\u001b[90m Char \u001b[0m\n",
       "─────┼─────────────\n",
       "   1 │     1  a\n",
       "   2 │     2  b"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x[1:2, :]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "a single row selection creates a `DataFrameRow`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<p>DataFrameRow (2 columns)</p><table class=\"data-frame\"><thead><tr><th></th><th>id</th><th>val</th></tr><tr><th></th><th>Int64</th><th>Char</th></tr></thead><tbody><tr><th>1</th><td>1</td><td>a</td></tr></tbody></table>"
      ],
      "text/latex": [
       "\\begin{tabular}{r|cc}\n",
       "\t& id & val\\\\\n",
       "\t\\hline\n",
       "\t& Int64 & Char\\\\\n",
       "\t\\hline\n",
       "\t1 & 1 & a \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/plain": [
       "\u001b[1mDataFrameRow\u001b[0m\n",
       "\u001b[1m Row \u001b[0m│\u001b[1m id    \u001b[0m\u001b[1m val  \u001b[0m\n",
       "\u001b[1m     \u001b[0m│\u001b[90m Int64 \u001b[0m\u001b[90m Char \u001b[0m\n",
       "─────┼─────────────\n",
       "   1 │     1  a"
      ]
     },
     "execution_count": 51,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x[1, :]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "but this is a `DataFrame`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table class=\"data-frame\"><thead><tr><th></th><th>id</th><th>val</th></tr><tr><th></th><th>Int64</th><th>Char</th></tr></thead><tbody><p>1 rows × 2 columns</p><tr><th>1</th><td>1</td><td>a</td></tr></tbody></table>"
      ],
      "text/latex": [
       "\\begin{tabular}{r|cc}\n",
       "\t& id & val\\\\\n",
       "\t\\hline\n",
       "\t& Int64 & Char\\\\\n",
       "\t\\hline\n",
       "\t1 & 1 & a \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/plain": [
       "\u001b[1m1×2 DataFrame\u001b[0m\n",
       "\u001b[1m Row \u001b[0m│\u001b[1m id    \u001b[0m\u001b[1m val  \u001b[0m\n",
       "\u001b[1m     \u001b[0m│\u001b[90m Int64 \u001b[0m\u001b[90m Char \u001b[0m\n",
       "─────┼─────────────\n",
       "   1 │     1  a"
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x[1:1, :]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "the same but a view"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table class=\"data-frame\"><thead><tr><th></th><th>id</th><th>val</th></tr><tr><th></th><th>Int64</th><th>Char</th></tr></thead><tbody><p>2 rows × 2 columns</p><tr><th>1</th><td>1</td><td>a</td></tr><tr><th>2</th><td>2</td><td>b</td></tr></tbody></table>"
      ],
      "text/latex": [
       "\\begin{tabular}{r|cc}\n",
       "\t& id & val\\\\\n",
       "\t\\hline\n",
       "\t& Int64 & Char\\\\\n",
       "\t\\hline\n",
       "\t1 & 1 & a \\\\\n",
       "\t2 & 2 & b \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/plain": [
       "\u001b[1m2×2 SubDataFrame\u001b[0m\n",
       "\u001b[1m Row \u001b[0m│\u001b[1m id    \u001b[0m\u001b[1m val  \u001b[0m\n",
       "\u001b[1m     \u001b[0m│\u001b[90m Int64 \u001b[0m\u001b[90m Char \u001b[0m\n",
       "─────┼─────────────\n",
       "   1 │     1  a\n",
       "   2 │     2  b"
      ]
     },
     "execution_count": 53,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "view(x, 1:2, :)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "selects columns 1 and 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table class=\"data-frame\"><thead><tr><th></th><th>id</th><th>val</th></tr><tr><th></th><th>Int64</th><th>Char</th></tr></thead><tbody><p>10 rows × 2 columns</p><tr><th>1</th><td>1</td><td>a</td></tr><tr><th>2</th><td>2</td><td>b</td></tr><tr><th>3</th><td>3</td><td>c</td></tr><tr><th>4</th><td>4</td><td>d</td></tr><tr><th>5</th><td>5</td><td>e</td></tr><tr><th>6</th><td>6</td><td>f</td></tr><tr><th>7</th><td>7</td><td>g</td></tr><tr><th>8</th><td>8</td><td>h</td></tr><tr><th>9</th><td>9</td><td>i</td></tr><tr><th>10</th><td>10</td><td>j</td></tr></tbody></table>"
      ],
      "text/latex": [
       "\\begin{tabular}{r|cc}\n",
       "\t& id & val\\\\\n",
       "\t\\hline\n",
       "\t& Int64 & Char\\\\\n",
       "\t\\hline\n",
       "\t1 & 1 & a \\\\\n",
       "\t2 & 2 & b \\\\\n",
       "\t3 & 3 & c \\\\\n",
       "\t4 & 4 & d \\\\\n",
       "\t5 & 5 & e \\\\\n",
       "\t6 & 6 & f \\\\\n",
       "\t7 & 7 & g \\\\\n",
       "\t8 & 8 & h \\\\\n",
       "\t9 & 9 & i \\\\\n",
       "\t10 & 10 & j \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/plain": [
       "\u001b[1m10×2 SubDataFrame\u001b[0m\n",
       "\u001b[1m Row \u001b[0m│\u001b[1m id    \u001b[0m\u001b[1m val  \u001b[0m\n",
       "\u001b[1m     \u001b[0m│\u001b[90m Int64 \u001b[0m\u001b[90m Char \u001b[0m\n",
       "─────┼─────────────\n",
       "   1 │     1  a\n",
       "   2 │     2  b\n",
       "   3 │     3  c\n",
       "   4 │     4  d\n",
       "   5 │     5  e\n",
       "   6 │     6  f\n",
       "   7 │     7  g\n",
       "   8 │     8  h\n",
       "   9 │     9  i\n",
       "  10 │    10  j"
      ]
     },
     "execution_count": 54,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "view(x, :, 1:2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "indexing by `Bool`, exact length math is required"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table class=\"data-frame\"><thead><tr><th></th><th>id</th><th>val</th></tr><tr><th></th><th>Int64</th><th>Char</th></tr></thead><tbody><p>5 rows × 2 columns</p><tr><th>1</th><td>1</td><td>a</td></tr><tr><th>2</th><td>3</td><td>c</td></tr><tr><th>3</th><td>5</td><td>e</td></tr><tr><th>4</th><td>7</td><td>g</td></tr><tr><th>5</th><td>9</td><td>i</td></tr></tbody></table>"
      ],
      "text/latex": [
       "\\begin{tabular}{r|cc}\n",
       "\t& id & val\\\\\n",
       "\t\\hline\n",
       "\t& Int64 & Char\\\\\n",
       "\t\\hline\n",
       "\t1 & 1 & a \\\\\n",
       "\t2 & 3 & c \\\\\n",
       "\t3 & 5 & e \\\\\n",
       "\t4 & 7 & g \\\\\n",
       "\t5 & 9 & i \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/plain": [
       "\u001b[1m5×2 DataFrame\u001b[0m\n",
       "\u001b[1m Row \u001b[0m│\u001b[1m id    \u001b[0m\u001b[1m val  \u001b[0m\n",
       "\u001b[1m     \u001b[0m│\u001b[90m Int64 \u001b[0m\u001b[90m Char \u001b[0m\n",
       "─────┼─────────────\n",
       "   1 │     1  a\n",
       "   2 │     3  c\n",
       "   3 │     5  e\n",
       "   4 │     7  g\n",
       "   5 │     9  i"
      ]
     },
     "execution_count": 55,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x[repeat([true, false], 5), :]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "alternatively we can also create a view"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table class=\"data-frame\"><thead><tr><th></th><th>id</th><th>val</th></tr><tr><th></th><th>Int64</th><th>Char</th></tr></thead><tbody><p>5 rows × 2 columns</p><tr><th>1</th><td>1</td><td>a</td></tr><tr><th>2</th><td>3</td><td>c</td></tr><tr><th>3</th><td>5</td><td>e</td></tr><tr><th>4</th><td>7</td><td>g</td></tr><tr><th>5</th><td>9</td><td>i</td></tr></tbody></table>"
      ],
      "text/latex": [
       "\\begin{tabular}{r|cc}\n",
       "\t& id & val\\\\\n",
       "\t\\hline\n",
       "\t& Int64 & Char\\\\\n",
       "\t\\hline\n",
       "\t1 & 1 & a \\\\\n",
       "\t2 & 3 & c \\\\\n",
       "\t3 & 5 & e \\\\\n",
       "\t4 & 7 & g \\\\\n",
       "\t5 & 9 & i \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/plain": [
       "\u001b[1m5×2 SubDataFrame\u001b[0m\n",
       "\u001b[1m Row \u001b[0m│\u001b[1m id    \u001b[0m\u001b[1m val  \u001b[0m\n",
       "\u001b[1m     \u001b[0m│\u001b[90m Int64 \u001b[0m\u001b[90m Char \u001b[0m\n",
       "─────┼─────────────\n",
       "   1 │     1  a\n",
       "   2 │     3  c\n",
       "   3 │     5  e\n",
       "   4 │     7  g\n",
       "   5 │     9  i"
      ]
     },
     "execution_count": 56,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "view(x, repeat([true, false], 5), :)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "we can delete one row in place"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table class=\"data-frame\"><thead><tr><th></th><th>id</th><th>val</th></tr><tr><th></th><th>Int64</th><th>Char</th></tr></thead><tbody><p>9 rows × 2 columns</p><tr><th>1</th><td>1</td><td>a</td></tr><tr><th>2</th><td>2</td><td>b</td></tr><tr><th>3</th><td>3</td><td>c</td></tr><tr><th>4</th><td>4</td><td>d</td></tr><tr><th>5</th><td>5</td><td>e</td></tr><tr><th>6</th><td>6</td><td>f</td></tr><tr><th>7</th><td>8</td><td>h</td></tr><tr><th>8</th><td>9</td><td>i</td></tr><tr><th>9</th><td>10</td><td>j</td></tr></tbody></table>"
      ],
      "text/latex": [
       "\\begin{tabular}{r|cc}\n",
       "\t& id & val\\\\\n",
       "\t\\hline\n",
       "\t& Int64 & Char\\\\\n",
       "\t\\hline\n",
       "\t1 & 1 & a \\\\\n",
       "\t2 & 2 & b \\\\\n",
       "\t3 & 3 & c \\\\\n",
       "\t4 & 4 & d \\\\\n",
       "\t5 & 5 & e \\\\\n",
       "\t6 & 6 & f \\\\\n",
       "\t7 & 8 & h \\\\\n",
       "\t8 & 9 & i \\\\\n",
       "\t9 & 10 & j \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/plain": [
       "\u001b[1m9×2 DataFrame\u001b[0m\n",
       "\u001b[1m Row \u001b[0m│\u001b[1m id    \u001b[0m\u001b[1m val  \u001b[0m\n",
       "\u001b[1m     \u001b[0m│\u001b[90m Int64 \u001b[0m\u001b[90m Char \u001b[0m\n",
       "─────┼─────────────\n",
       "   1 │     1  a\n",
       "   2 │     2  b\n",
       "   3 │     3  c\n",
       "   4 │     4  d\n",
       "   5 │     5  e\n",
       "   6 │     6  f\n",
       "   7 │     8  h\n",
       "   8 │     9  i\n",
       "   9 │    10  j"
      ]
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "delete!(x, 7)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "or a collection of rows, also in place"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table class=\"data-frame\"><thead><tr><th></th><th>id</th><th>val</th></tr><tr><th></th><th>Int64</th><th>Char</th></tr></thead><tbody><p>7 rows × 2 columns</p><tr><th>1</th><td>1</td><td>a</td></tr><tr><th>2</th><td>2</td><td>b</td></tr><tr><th>3</th><td>3</td><td>c</td></tr><tr><th>4</th><td>4</td><td>d</td></tr><tr><th>5</th><td>5</td><td>e</td></tr><tr><th>6</th><td>9</td><td>i</td></tr><tr><th>7</th><td>10</td><td>j</td></tr></tbody></table>"
      ],
      "text/latex": [
       "\\begin{tabular}{r|cc}\n",
       "\t& id & val\\\\\n",
       "\t\\hline\n",
       "\t& Int64 & Char\\\\\n",
       "\t\\hline\n",
       "\t1 & 1 & a \\\\\n",
       "\t2 & 2 & b \\\\\n",
       "\t3 & 3 & c \\\\\n",
       "\t4 & 4 & d \\\\\n",
       "\t5 & 5 & e \\\\\n",
       "\t6 & 9 & i \\\\\n",
       "\t7 & 10 & j \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/plain": [
       "\u001b[1m7×2 DataFrame\u001b[0m\n",
       "\u001b[1m Row \u001b[0m│\u001b[1m id    \u001b[0m\u001b[1m val  \u001b[0m\n",
       "\u001b[1m     \u001b[0m│\u001b[90m Int64 \u001b[0m\u001b[90m Char \u001b[0m\n",
       "─────┼─────────────\n",
       "   1 │     1  a\n",
       "   2 │     2  b\n",
       "   3 │     3  c\n",
       "   4 │     4  d\n",
       "   5 │     5  e\n",
       "   6 │     9  i\n",
       "   7 │    10  j"
      ]
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "delete!(x, 6:7)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "you can also create a new `DataFrame` when deleting rows using `Not` indexing"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table class=\"data-frame\"><thead><tr><th></th><th>id</th><th>val</th></tr><tr><th></th><th>Int64</th><th>Char</th></tr></thead><tbody><p>5 rows × 2 columns</p><tr><th>1</th><td>3</td><td>c</td></tr><tr><th>2</th><td>4</td><td>d</td></tr><tr><th>3</th><td>5</td><td>e</td></tr><tr><th>4</th><td>9</td><td>i</td></tr><tr><th>5</th><td>10</td><td>j</td></tr></tbody></table>"
      ],
      "text/latex": [
       "\\begin{tabular}{r|cc}\n",
       "\t& id & val\\\\\n",
       "\t\\hline\n",
       "\t& Int64 & Char\\\\\n",
       "\t\\hline\n",
       "\t1 & 3 & c \\\\\n",
       "\t2 & 4 & d \\\\\n",
       "\t3 & 5 & e \\\\\n",
       "\t4 & 9 & i \\\\\n",
       "\t5 & 10 & j \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/plain": [
       "\u001b[1m5×2 DataFrame\u001b[0m\n",
       "\u001b[1m Row \u001b[0m│\u001b[1m id    \u001b[0m\u001b[1m val  \u001b[0m\n",
       "\u001b[1m     \u001b[0m│\u001b[90m Int64 \u001b[0m\u001b[90m Char \u001b[0m\n",
       "─────┼─────────────\n",
       "   1 │     3  c\n",
       "   2 │     4  d\n",
       "   3 │     5  e\n",
       "   4 │     9  i\n",
       "   5 │    10  j"
      ]
     },
     "execution_count": 59,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x[Not(1:2), :]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table class=\"data-frame\"><thead><tr><th></th><th>id</th><th>val</th></tr><tr><th></th><th>Int64</th><th>Char</th></tr></thead><tbody><p>7 rows × 2 columns</p><tr><th>1</th><td>1</td><td>a</td></tr><tr><th>2</th><td>2</td><td>b</td></tr><tr><th>3</th><td>3</td><td>c</td></tr><tr><th>4</th><td>4</td><td>d</td></tr><tr><th>5</th><td>5</td><td>e</td></tr><tr><th>6</th><td>9</td><td>i</td></tr><tr><th>7</th><td>10</td><td>j</td></tr></tbody></table>"
      ],
      "text/latex": [
       "\\begin{tabular}{r|cc}\n",
       "\t& id & val\\\\\n",
       "\t\\hline\n",
       "\t& Int64 & Char\\\\\n",
       "\t\\hline\n",
       "\t1 & 1 & a \\\\\n",
       "\t2 & 2 & b \\\\\n",
       "\t3 & 3 & c \\\\\n",
       "\t4 & 4 & d \\\\\n",
       "\t5 & 5 & e \\\\\n",
       "\t6 & 9 & i \\\\\n",
       "\t7 & 10 & j \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/plain": [
       "\u001b[1m7×2 DataFrame\u001b[0m\n",
       "\u001b[1m Row \u001b[0m│\u001b[1m id    \u001b[0m\u001b[1m val  \u001b[0m\n",
       "\u001b[1m     \u001b[0m│\u001b[90m Int64 \u001b[0m\u001b[90m Char \u001b[0m\n",
       "─────┼─────────────\n",
       "   1 │     1  a\n",
       "   2 │     2  b\n",
       "   3 │     3  c\n",
       "   4 │     4  d\n",
       "   5 │     5  e\n",
       "   6 │     9  i\n",
       "   7 │    10  j"
      ]
     },
     "execution_count": 60,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "now we move to row filtering"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table class=\"data-frame\"><thead><tr><th></th><th>x1</th><th>x2</th><th>x3</th></tr><tr><th></th><th>Int64</th><th>Int64</th><th>Int64</th></tr></thead><tbody><p>4 rows × 3 columns</p><tr><th>1</th><td>1</td><td>2</td><td>3</td></tr><tr><th>2</th><td>2</td><td>3</td><td>4</td></tr><tr><th>3</th><td>3</td><td>4</td><td>5</td></tr><tr><th>4</th><td>4</td><td>5</td><td>6</td></tr></tbody></table>"
      ],
      "text/latex": [
       "\\begin{tabular}{r|ccc}\n",
       "\t& x1 & x2 & x3\\\\\n",
       "\t\\hline\n",
       "\t& Int64 & Int64 & Int64\\\\\n",
       "\t\\hline\n",
       "\t1 & 1 & 2 & 3 \\\\\n",
       "\t2 & 2 & 3 & 4 \\\\\n",
       "\t3 & 3 & 4 & 5 \\\\\n",
       "\t4 & 4 & 5 & 6 \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/plain": [
       "\u001b[1m4×3 DataFrame\u001b[0m\n",
       "\u001b[1m Row \u001b[0m│\u001b[1m x1    \u001b[0m\u001b[1m x2    \u001b[0m\u001b[1m x3    \u001b[0m\n",
       "\u001b[1m     \u001b[0m│\u001b[90m Int64 \u001b[0m\u001b[90m Int64 \u001b[0m\u001b[90m Int64 \u001b[0m\n",
       "─────┼─────────────────────\n",
       "   1 │     1      2      3\n",
       "   2 │     2      3      4\n",
       "   3 │     3      4      5\n",
       "   4 │     4      5      6"
      ]
     },
     "execution_count": 61,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x = DataFrame([1:4, 2:5, 3:6], :auto)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "create a new `DataFrame` where filtering function operates on `DataFrameRow`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table class=\"data-frame\"><thead><tr><th></th><th>x1</th><th>x2</th><th>x3</th></tr><tr><th></th><th>Int64</th><th>Int64</th><th>Int64</th></tr></thead><tbody><p>2 rows × 3 columns</p><tr><th>1</th><td>3</td><td>4</td><td>5</td></tr><tr><th>2</th><td>4</td><td>5</td><td>6</td></tr></tbody></table>"
      ],
      "text/latex": [
       "\\begin{tabular}{r|ccc}\n",
       "\t& x1 & x2 & x3\\\\\n",
       "\t\\hline\n",
       "\t& Int64 & Int64 & Int64\\\\\n",
       "\t\\hline\n",
       "\t1 & 3 & 4 & 5 \\\\\n",
       "\t2 & 4 & 5 & 6 \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/plain": [
       "\u001b[1m2×3 DataFrame\u001b[0m\n",
       "\u001b[1m Row \u001b[0m│\u001b[1m x1    \u001b[0m\u001b[1m x2    \u001b[0m\u001b[1m x3    \u001b[0m\n",
       "\u001b[1m     \u001b[0m│\u001b[90m Int64 \u001b[0m\u001b[90m Int64 \u001b[0m\u001b[90m Int64 \u001b[0m\n",
       "─────┼─────────────────────\n",
       "   1 │     3      4      5\n",
       "   2 │     4      5      6"
      ]
     },
     "execution_count": 62,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "filter(r -> r.x1 > 2.5, x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table class=\"data-frame\"><thead><tr><th></th><th>x1</th><th>x2</th><th>x3</th></tr><tr><th></th><th>Int64</th><th>Int64</th><th>Int64</th></tr></thead><tbody><p>2 rows × 3 columns</p><tr><th>1</th><td>3</td><td>4</td><td>5</td></tr><tr><th>2</th><td>4</td><td>5</td><td>6</td></tr></tbody></table>"
      ],
      "text/latex": [
       "\\begin{tabular}{r|ccc}\n",
       "\t& x1 & x2 & x3\\\\\n",
       "\t\\hline\n",
       "\t& Int64 & Int64 & Int64\\\\\n",
       "\t\\hline\n",
       "\t1 & 3 & 4 & 5 \\\\\n",
       "\t2 & 4 & 5 & 6 \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/plain": [
       "\u001b[1m2×3 SubDataFrame\u001b[0m\n",
       "\u001b[1m Row \u001b[0m│\u001b[1m x1    \u001b[0m\u001b[1m x2    \u001b[0m\u001b[1m x3    \u001b[0m\n",
       "\u001b[1m     \u001b[0m│\u001b[90m Int64 \u001b[0m\u001b[90m Int64 \u001b[0m\u001b[90m Int64 \u001b[0m\n",
       "─────┼─────────────────────\n",
       "   1 │     3      4      5\n",
       "   2 │     4      5      6"
      ]
     },
     "execution_count": 63,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "filter(r -> r.x1 > 2.5, x, view=true) # the same but as a view"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "or"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table class=\"data-frame\"><thead><tr><th></th><th>x1</th><th>x2</th><th>x3</th></tr><tr><th></th><th>Int64</th><th>Int64</th><th>Int64</th></tr></thead><tbody><p>2 rows × 3 columns</p><tr><th>1</th><td>3</td><td>4</td><td>5</td></tr><tr><th>2</th><td>4</td><td>5</td><td>6</td></tr></tbody></table>"
      ],
      "text/latex": [
       "\\begin{tabular}{r|ccc}\n",
       "\t& x1 & x2 & x3\\\\\n",
       "\t\\hline\n",
       "\t& Int64 & Int64 & Int64\\\\\n",
       "\t\\hline\n",
       "\t1 & 3 & 4 & 5 \\\\\n",
       "\t2 & 4 & 5 & 6 \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/plain": [
       "\u001b[1m2×3 DataFrame\u001b[0m\n",
       "\u001b[1m Row \u001b[0m│\u001b[1m x1    \u001b[0m\u001b[1m x2    \u001b[0m\u001b[1m x3    \u001b[0m\n",
       "\u001b[1m     \u001b[0m│\u001b[90m Int64 \u001b[0m\u001b[90m Int64 \u001b[0m\u001b[90m Int64 \u001b[0m\n",
       "─────┼─────────────────────\n",
       "   1 │     3      4      5\n",
       "   2 │     4      5      6"
      ]
     },
     "execution_count": 64,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "filter(:x1 => >(2.5), x)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "in place modification of `x`, an example with `do`-block syntax"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table class=\"data-frame\"><thead><tr><th></th><th>x1</th><th>x2</th><th>x3</th></tr><tr><th></th><th>Int64</th><th>Int64</th><th>Int64</th></tr></thead><tbody><p>2 rows × 3 columns</p><tr><th>1</th><td>1</td><td>2</td><td>3</td></tr><tr><th>2</th><td>3</td><td>4</td><td>5</td></tr></tbody></table>"
      ],
      "text/latex": [
       "\\begin{tabular}{r|ccc}\n",
       "\t& x1 & x2 & x3\\\\\n",
       "\t\\hline\n",
       "\t& Int64 & Int64 & Int64\\\\\n",
       "\t\\hline\n",
       "\t1 & 1 & 2 & 3 \\\\\n",
       "\t2 & 3 & 4 & 5 \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/plain": [
       "\u001b[1m2×3 DataFrame\u001b[0m\n",
       "\u001b[1m Row \u001b[0m│\u001b[1m x1    \u001b[0m\u001b[1m x2    \u001b[0m\u001b[1m x3    \u001b[0m\n",
       "\u001b[1m     \u001b[0m│\u001b[90m Int64 \u001b[0m\u001b[90m Int64 \u001b[0m\u001b[90m Int64 \u001b[0m\n",
       "─────┼─────────────────────\n",
       "   1 │     1      2      3\n",
       "   2 │     3      4      5"
      ]
     },
     "execution_count": 65,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "filter!(x) do r\n",
    "    if r.x1 > 2.5\n",
    "        return r.x2 < 4.5\n",
    "    end\n",
    "    r.x3 < 3.5\n",
    "end"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "A common operation is selection of rows for which a value in a column is contained in a given set. Here are a few ways in which you can achieve this."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table class=\"data-frame\"><thead><tr><th></th><th>x</th><th>y</th></tr><tr><th></th><th>Int64</th><th>Int64</th></tr></thead><tbody><p>12 rows × 2 columns</p><tr><th>1</th><td>1</td><td>1</td></tr><tr><th>2</th><td>2</td><td>2</td></tr><tr><th>3</th><td>3</td><td>3</td></tr><tr><th>4</th><td>4</td><td>4</td></tr><tr><th>5</th><td>5</td><td>1</td></tr><tr><th>6</th><td>6</td><td>2</td></tr><tr><th>7</th><td>7</td><td>3</td></tr><tr><th>8</th><td>8</td><td>4</td></tr><tr><th>9</th><td>9</td><td>1</td></tr><tr><th>10</th><td>10</td><td>2</td></tr><tr><th>11</th><td>11</td><td>3</td></tr><tr><th>12</th><td>12</td><td>4</td></tr></tbody></table>"
      ],
      "text/latex": [
       "\\begin{tabular}{r|cc}\n",
       "\t& x & y\\\\\n",
       "\t\\hline\n",
       "\t& Int64 & Int64\\\\\n",
       "\t\\hline\n",
       "\t1 & 1 & 1 \\\\\n",
       "\t2 & 2 & 2 \\\\\n",
       "\t3 & 3 & 3 \\\\\n",
       "\t4 & 4 & 4 \\\\\n",
       "\t5 & 5 & 1 \\\\\n",
       "\t6 & 6 & 2 \\\\\n",
       "\t7 & 7 & 3 \\\\\n",
       "\t8 & 8 & 4 \\\\\n",
       "\t9 & 9 & 1 \\\\\n",
       "\t10 & 10 & 2 \\\\\n",
       "\t11 & 11 & 3 \\\\\n",
       "\t12 & 12 & 4 \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/plain": [
       "\u001b[1m12×2 DataFrame\u001b[0m\n",
       "\u001b[1m Row \u001b[0m│\u001b[1m x     \u001b[0m\u001b[1m y     \u001b[0m\n",
       "\u001b[1m     \u001b[0m│\u001b[90m Int64 \u001b[0m\u001b[90m Int64 \u001b[0m\n",
       "─────┼──────────────\n",
       "   1 │     1      1\n",
       "   2 │     2      2\n",
       "   3 │     3      3\n",
       "   4 │     4      4\n",
       "   5 │     5      1\n",
       "   6 │     6      2\n",
       "   7 │     7      3\n",
       "   8 │     8      4\n",
       "   9 │     9      1\n",
       "  10 │    10      2\n",
       "  11 │    11      3\n",
       "  12 │    12      4"
      ]
     },
     "execution_count": 66,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = DataFrame(x=1:12, y=mod1.(1:12, 4))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We select rows for which column `y` has value `1` or `4`."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table class=\"data-frame\"><thead><tr><th></th><th>x</th><th>y</th></tr><tr><th></th><th>Int64</th><th>Int64</th></tr></thead><tbody><p>6 rows × 2 columns</p><tr><th>1</th><td>1</td><td>1</td></tr><tr><th>2</th><td>4</td><td>4</td></tr><tr><th>3</th><td>5</td><td>1</td></tr><tr><th>4</th><td>8</td><td>4</td></tr><tr><th>5</th><td>9</td><td>1</td></tr><tr><th>6</th><td>12</td><td>4</td></tr></tbody></table>"
      ],
      "text/latex": [
       "\\begin{tabular}{r|cc}\n",
       "\t& x & y\\\\\n",
       "\t\\hline\n",
       "\t& Int64 & Int64\\\\\n",
       "\t\\hline\n",
       "\t1 & 1 & 1 \\\\\n",
       "\t2 & 4 & 4 \\\\\n",
       "\t3 & 5 & 1 \\\\\n",
       "\t4 & 8 & 4 \\\\\n",
       "\t5 & 9 & 1 \\\\\n",
       "\t6 & 12 & 4 \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/plain": [
       "\u001b[1m6×2 DataFrame\u001b[0m\n",
       "\u001b[1m Row \u001b[0m│\u001b[1m x     \u001b[0m\u001b[1m y     \u001b[0m\n",
       "\u001b[1m     \u001b[0m│\u001b[90m Int64 \u001b[0m\u001b[90m Int64 \u001b[0m\n",
       "─────┼──────────────\n",
       "   1 │     1      1\n",
       "   2 │     4      4\n",
       "   3 │     5      1\n",
       "   4 │     8      4\n",
       "   5 │     9      1\n",
       "   6 │    12      4"
      ]
     },
     "execution_count": 67,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "filter(row -> row.y in [1,4], df)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table class=\"data-frame\"><thead><tr><th></th><th>x</th><th>y</th></tr><tr><th></th><th>Int64</th><th>Int64</th></tr></thead><tbody><p>6 rows × 2 columns</p><tr><th>1</th><td>1</td><td>1</td></tr><tr><th>2</th><td>4</td><td>4</td></tr><tr><th>3</th><td>5</td><td>1</td></tr><tr><th>4</th><td>8</td><td>4</td></tr><tr><th>5</th><td>9</td><td>1</td></tr><tr><th>6</th><td>12</td><td>4</td></tr></tbody></table>"
      ],
      "text/latex": [
       "\\begin{tabular}{r|cc}\n",
       "\t& x & y\\\\\n",
       "\t\\hline\n",
       "\t& Int64 & Int64\\\\\n",
       "\t\\hline\n",
       "\t1 & 1 & 1 \\\\\n",
       "\t2 & 4 & 4 \\\\\n",
       "\t3 & 5 & 1 \\\\\n",
       "\t4 & 8 & 4 \\\\\n",
       "\t5 & 9 & 1 \\\\\n",
       "\t6 & 12 & 4 \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/plain": [
       "\u001b[1m6×2 DataFrame\u001b[0m\n",
       "\u001b[1m Row \u001b[0m│\u001b[1m x     \u001b[0m\u001b[1m y     \u001b[0m\n",
       "\u001b[1m     \u001b[0m│\u001b[90m Int64 \u001b[0m\u001b[90m Int64 \u001b[0m\n",
       "─────┼──────────────\n",
       "   1 │     1      1\n",
       "   2 │     4      4\n",
       "   3 │     5      1\n",
       "   4 │     8      4\n",
       "   5 │     9      1\n",
       "   6 │    12      4"
      ]
     },
     "execution_count": 68,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "filter(:y => in([1,4]), df)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table class=\"data-frame\"><thead><tr><th></th><th>x</th><th>y</th></tr><tr><th></th><th>Int64</th><th>Int64</th></tr></thead><tbody><p>6 rows × 2 columns</p><tr><th>1</th><td>1</td><td>1</td></tr><tr><th>2</th><td>4</td><td>4</td></tr><tr><th>3</th><td>5</td><td>1</td></tr><tr><th>4</th><td>8</td><td>4</td></tr><tr><th>5</th><td>9</td><td>1</td></tr><tr><th>6</th><td>12</td><td>4</td></tr></tbody></table>"
      ],
      "text/latex": [
       "\\begin{tabular}{r|cc}\n",
       "\t& x & y\\\\\n",
       "\t\\hline\n",
       "\t& Int64 & Int64\\\\\n",
       "\t\\hline\n",
       "\t1 & 1 & 1 \\\\\n",
       "\t2 & 4 & 4 \\\\\n",
       "\t3 & 5 & 1 \\\\\n",
       "\t4 & 8 & 4 \\\\\n",
       "\t5 & 9 & 1 \\\\\n",
       "\t6 & 12 & 4 \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/plain": [
       "\u001b[1m6×2 DataFrame\u001b[0m\n",
       "\u001b[1m Row \u001b[0m│\u001b[1m x     \u001b[0m\u001b[1m y     \u001b[0m\n",
       "\u001b[1m     \u001b[0m│\u001b[90m Int64 \u001b[0m\u001b[90m Int64 \u001b[0m\n",
       "─────┼──────────────\n",
       "   1 │     1      1\n",
       "   2 │     4      4\n",
       "   3 │     5      1\n",
       "   4 │     8      4\n",
       "   5 │     9      1\n",
       "   6 │    12      4"
      ]
     },
     "execution_count": 69,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[in.(df.y, Ref([1,4])), :]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Deduplicating"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table class=\"data-frame\"><thead><tr><th></th><th>A</th><th>B</th><th>C</th></tr><tr><th></th><th>Int64</th><th>String</th><th>Int64</th></tr></thead><tbody><p>4 rows × 3 columns</p><tr><th>1</th><td>1</td><td>x</td><td>1</td></tr><tr><th>2</th><td>2</td><td>y</td><td>2</td></tr><tr><th>3</th><td>1</td><td>x</td><td>3</td></tr><tr><th>4</th><td>2</td><td>y</td><td>4</td></tr></tbody></table>"
      ],
      "text/latex": [
       "\\begin{tabular}{r|ccc}\n",
       "\t& A & B & C\\\\\n",
       "\t\\hline\n",
       "\t& Int64 & String & Int64\\\\\n",
       "\t\\hline\n",
       "\t1 & 1 & x & 1 \\\\\n",
       "\t2 & 2 & y & 2 \\\\\n",
       "\t3 & 1 & x & 3 \\\\\n",
       "\t4 & 2 & y & 4 \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/plain": [
       "\u001b[1m4×3 DataFrame\u001b[0m\n",
       "\u001b[1m Row \u001b[0m│\u001b[1m A     \u001b[0m\u001b[1m B      \u001b[0m\u001b[1m C     \u001b[0m\n",
       "\u001b[1m     \u001b[0m│\u001b[90m Int64 \u001b[0m\u001b[90m String \u001b[0m\u001b[90m Int64 \u001b[0m\n",
       "─────┼──────────────────────\n",
       "   1 │     1  x           1\n",
       "   2 │     2  y           2\n",
       "   3 │     1  x           3\n",
       "   4 │     2  y           4"
      ]
     },
     "execution_count": 70,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x = DataFrame(A=[1,2], B=[\"x\",\"y\"])\n",
    "append!(x, x)\n",
    "x.C = 1:4\n",
    "x"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "get first unique rows for given index"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table class=\"data-frame\"><thead><tr><th></th><th>A</th><th>B</th><th>C</th></tr><tr><th></th><th>Int64</th><th>String</th><th>Int64</th></tr></thead><tbody><p>2 rows × 3 columns</p><tr><th>1</th><td>1</td><td>x</td><td>1</td></tr><tr><th>2</th><td>2</td><td>y</td><td>2</td></tr></tbody></table>"
      ],
      "text/latex": [
       "\\begin{tabular}{r|ccc}\n",
       "\t& A & B & C\\\\\n",
       "\t\\hline\n",
       "\t& Int64 & String & Int64\\\\\n",
       "\t\\hline\n",
       "\t1 & 1 & x & 1 \\\\\n",
       "\t2 & 2 & y & 2 \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/plain": [
       "\u001b[1m2×3 DataFrame\u001b[0m\n",
       "\u001b[1m Row \u001b[0m│\u001b[1m A     \u001b[0m\u001b[1m B      \u001b[0m\u001b[1m C     \u001b[0m\n",
       "\u001b[1m     \u001b[0m│\u001b[90m Int64 \u001b[0m\u001b[90m String \u001b[0m\u001b[90m Int64 \u001b[0m\n",
       "─────┼──────────────────────\n",
       "   1 │     1  x           1\n",
       "   2 │     2  y           2"
      ]
     },
     "execution_count": 71,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "unique(x, [1,2])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "now we look at whole rows"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table class=\"data-frame\"><thead><tr><th></th><th>A</th><th>B</th><th>C</th></tr><tr><th></th><th>Int64</th><th>String</th><th>Int64</th></tr></thead><tbody><p>4 rows × 3 columns</p><tr><th>1</th><td>1</td><td>x</td><td>1</td></tr><tr><th>2</th><td>2</td><td>y</td><td>2</td></tr><tr><th>3</th><td>1</td><td>x</td><td>3</td></tr><tr><th>4</th><td>2</td><td>y</td><td>4</td></tr></tbody></table>"
      ],
      "text/latex": [
       "\\begin{tabular}{r|ccc}\n",
       "\t& A & B & C\\\\\n",
       "\t\\hline\n",
       "\t& Int64 & String & Int64\\\\\n",
       "\t\\hline\n",
       "\t1 & 1 & x & 1 \\\\\n",
       "\t2 & 2 & y & 2 \\\\\n",
       "\t3 & 1 & x & 3 \\\\\n",
       "\t4 & 2 & y & 4 \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/plain": [
       "\u001b[1m4×3 DataFrame\u001b[0m\n",
       "\u001b[1m Row \u001b[0m│\u001b[1m A     \u001b[0m\u001b[1m B      \u001b[0m\u001b[1m C     \u001b[0m\n",
       "\u001b[1m     \u001b[0m│\u001b[90m Int64 \u001b[0m\u001b[90m String \u001b[0m\u001b[90m Int64 \u001b[0m\n",
       "─────┼──────────────────────\n",
       "   1 │     1  x           1\n",
       "   2 │     2  y           2\n",
       "   3 │     1  x           3\n",
       "   4 │     2  y           4"
      ]
     },
     "execution_count": 72,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "unique(x)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "get indicators of non-unique rows"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4-element Array{Bool,1}:\n",
       " 0\n",
       " 0\n",
       " 1\n",
       " 1"
      ]
     },
     "execution_count": 73,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nonunique(x, :A)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "modify `x` in place"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table class=\"data-frame\"><thead><tr><th></th><th>A</th><th>B</th><th>C</th></tr><tr><th></th><th>Int64</th><th>String</th><th>Int64</th></tr></thead><tbody><p>2 rows × 3 columns</p><tr><th>1</th><td>1</td><td>x</td><td>1</td></tr><tr><th>2</th><td>2</td><td>y</td><td>2</td></tr></tbody></table>"
      ],
      "text/latex": [
       "\\begin{tabular}{r|ccc}\n",
       "\t& A & B & C\\\\\n",
       "\t\\hline\n",
       "\t& Int64 & String & Int64\\\\\n",
       "\t\\hline\n",
       "\t1 & 1 & x & 1 \\\\\n",
       "\t2 & 2 & y & 2 \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/plain": [
       "\u001b[1m2×3 DataFrame\u001b[0m\n",
       "\u001b[1m Row \u001b[0m│\u001b[1m A     \u001b[0m\u001b[1m B      \u001b[0m\u001b[1m C     \u001b[0m\n",
       "\u001b[1m     \u001b[0m│\u001b[90m Int64 \u001b[0m\u001b[90m String \u001b[0m\u001b[90m Int64 \u001b[0m\n",
       "─────┼──────────────────────\n",
       "   1 │     1  x           1\n",
       "   2 │     2  y           2"
      ]
     },
     "execution_count": 74,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "unique!(x, :B)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Extracting one row from a `DataFrame` into standard collections"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table class=\"data-frame\"><thead><tr><th></th><th>x</th><th>y</th><th>z</th></tr><tr><th></th><th>Int64?</th><th>String?</th><th>Bool</th></tr></thead><tbody><p>3 rows × 3 columns</p><tr><th>1</th><td>1</td><td>a</td><td>1</td></tr><tr><th>2</th><td><em>missing</em></td><td>b</td><td>0</td></tr><tr><th>3</th><td>2</td><td><em>missing</em></td><td>1</td></tr></tbody></table>"
      ],
      "text/latex": [
       "\\begin{tabular}{r|ccc}\n",
       "\t& x & y & z\\\\\n",
       "\t\\hline\n",
       "\t& Int64? & String? & Bool\\\\\n",
       "\t\\hline\n",
       "\t1 & 1 & a & 1 \\\\\n",
       "\t2 & \\emph{missing} & b & 0 \\\\\n",
       "\t3 & 2 & \\emph{missing} & 1 \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/plain": [
       "\u001b[1m3×3 DataFrame\u001b[0m\n",
       "\u001b[1m Row \u001b[0m│\u001b[1m x       \u001b[0m\u001b[1m y       \u001b[0m\u001b[1m z     \u001b[0m\n",
       "\u001b[1m     \u001b[0m│\u001b[90m Int64?  \u001b[0m\u001b[90m String? \u001b[0m\u001b[90m Bool  \u001b[0m\n",
       "─────┼─────────────────────────\n",
       "   1 │       1  a         true\n",
       "   2 │\u001b[90m missing \u001b[0m b        false\n",
       "   3 │       2 \u001b[90m missing \u001b[0m  true"
      ]
     },
     "execution_count": 75,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x = DataFrame(x=[1,missing,2], y=[\"a\", \"b\", missing], z=[true,false,true])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2-element Array{Symbol,1}:\n",
       " :y\n",
       " :z"
      ]
     },
     "execution_count": 76,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cols = [:y, :z]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "you can use a conversion to a `Vector` or an `Array`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 77,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2-element Array{Any,1}:\n",
       "     \"a\"\n",
       " true"
      ]
     },
     "execution_count": 77,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Vector(x[1, cols])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 78,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2-element Array{Any,1}:\n",
       "     \"a\"\n",
       " true"
      ]
     },
     "execution_count": 78,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Array(x[1, cols]) # the same"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "now you will get a vector of vectors"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3-element Array{Array{Any,1},1}:\n",
       " [\"a\", true]\n",
       " [\"b\", false]\n",
       " [missing, true]"
      ]
     },
     "execution_count": 79,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "[Vector(x[i, cols]) for i in axes(x, 1)]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "it is easy to convert a `DataFrameRow` into a `NamedTuple`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 80,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "NamedTuple{(:y, :z),Tuple{Union{Missing, String},Bool}}((\"a\", true))"
      ]
     },
     "execution_count": 80,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "copy(x[1, cols])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "or a `Tuple`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 81,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(\"a\", true)"
      ]
     },
     "execution_count": 81,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Tuple(x[1, cols])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Working with a collection of rows of a data frame"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "You can use `eachrow` to get a vector-like collection of `DataFrameRow`s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 82,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table class=\"data-frame\"><thead><tr><th></th><th>x1</th><th>x2</th><th>x3</th><th>x4</th></tr><tr><th></th><th>Int64</th><th>Int64</th><th>Int64</th><th>Int64</th></tr></thead><tbody><p>3 rows × 4 columns</p><tr><th>1</th><td>1</td><td>4</td><td>7</td><td>10</td></tr><tr><th>2</th><td>2</td><td>5</td><td>8</td><td>11</td></tr><tr><th>3</th><td>3</td><td>6</td><td>9</td><td>12</td></tr></tbody></table>"
      ],
      "text/latex": [
       "\\begin{tabular}{r|cccc}\n",
       "\t& x1 & x2 & x3 & x4\\\\\n",
       "\t\\hline\n",
       "\t& Int64 & Int64 & Int64 & Int64\\\\\n",
       "\t\\hline\n",
       "\t1 & 1 & 4 & 7 & 10 \\\\\n",
       "\t2 & 2 & 5 & 8 & 11 \\\\\n",
       "\t3 & 3 & 6 & 9 & 12 \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/plain": [
       "\u001b[1m3×4 DataFrame\u001b[0m\n",
       "\u001b[1m Row \u001b[0m│\u001b[1m x1    \u001b[0m\u001b[1m x2    \u001b[0m\u001b[1m x3    \u001b[0m\u001b[1m x4    \u001b[0m\n",
       "\u001b[1m     \u001b[0m│\u001b[90m Int64 \u001b[0m\u001b[90m Int64 \u001b[0m\u001b[90m Int64 \u001b[0m\u001b[90m Int64 \u001b[0m\n",
       "─────┼────────────────────────────\n",
       "   1 │     1      4      7     10\n",
       "   2 │     2      5      8     11\n",
       "   3 │     3      6      9     12"
      ]
     },
     "execution_count": 82,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = DataFrame(reshape(1:12, 3, 4), :auto)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 83,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<p>3×4 DataFrameRows</p><table class=\"data-frame\"><thead><tr><th></th><th>x1</th><th>x2</th><th>x3</th><th>x4</th></tr><tr><th></th><th>Int64</th><th>Int64</th><th>Int64</th><th>Int64</th></tr></thead><tbody><tr><th>1</th><td>1</td><td>4</td><td>7</td><td>10</td></tr><tr><th>2</th><td>2</td><td>5</td><td>8</td><td>11</td></tr><tr><th>3</th><td>3</td><td>6</td><td>9</td><td>12</td></tr></tbody></table>"
      ],
      "text/latex": [
       "\\begin{tabular}{r|cccc}\n",
       "\t& x1 & x2 & x3 & x4\\\\\n",
       "\t\\hline\n",
       "\t& Int64 & Int64 & Int64 & Int64\\\\\n",
       "\t\\hline\n",
       "\t1 & 1 & 4 & 7 & 10 \\\\\n",
       "\t2 & 2 & 5 & 8 & 11 \\\\\n",
       "\t3 & 3 & 6 & 9 & 12 \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/plain": [
       "\u001b[1m3×4 DataFrameRows\u001b[0m\n",
       "\u001b[1m Row \u001b[0m│\u001b[1m x1    \u001b[0m\u001b[1m x2    \u001b[0m\u001b[1m x3    \u001b[0m\u001b[1m x4    \u001b[0m\n",
       "\u001b[1m     \u001b[0m│\u001b[90m Int64 \u001b[0m\u001b[90m Int64 \u001b[0m\u001b[90m Int64 \u001b[0m\u001b[90m Int64 \u001b[0m\n",
       "─────┼────────────────────────────\n",
       "   1 │     1      4      7     10\n",
       "   2 │     2      5      8     11\n",
       "   3 │     3      6      9     12"
      ]
     },
     "execution_count": 83,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "er_df = eachrow(df)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 84,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<p>DataFrameRow (4 columns)</p><table class=\"data-frame\"><thead><tr><th></th><th>x1</th><th>x2</th><th>x3</th><th>x4</th></tr><tr><th></th><th>Int64</th><th>Int64</th><th>Int64</th><th>Int64</th></tr></thead><tbody><tr><th>1</th><td>1</td><td>4</td><td>7</td><td>10</td></tr></tbody></table>"
      ],
      "text/latex": [
       "\\begin{tabular}{r|cccc}\n",
       "\t& x1 & x2 & x3 & x4\\\\\n",
       "\t\\hline\n",
       "\t& Int64 & Int64 & Int64 & Int64\\\\\n",
       "\t\\hline\n",
       "\t1 & 1 & 4 & 7 & 10 \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/plain": [
       "\u001b[1mDataFrameRow\u001b[0m\n",
       "\u001b[1m Row \u001b[0m│\u001b[1m x1    \u001b[0m\u001b[1m x2    \u001b[0m\u001b[1m x3    \u001b[0m\u001b[1m x4    \u001b[0m\n",
       "\u001b[1m     \u001b[0m│\u001b[90m Int64 \u001b[0m\u001b[90m Int64 \u001b[0m\u001b[90m Int64 \u001b[0m\u001b[90m Int64 \u001b[0m\n",
       "─────┼────────────────────────────\n",
       "   1 │     1      4      7     10"
      ]
     },
     "execution_count": 84,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "er_df[1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 85,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<p>DataFrameRow (4 columns)</p><table class=\"data-frame\"><thead><tr><th></th><th>x1</th><th>x2</th><th>x3</th><th>x4</th></tr><tr><th></th><th>Int64</th><th>Int64</th><th>Int64</th><th>Int64</th></tr></thead><tbody><tr><th>3</th><td>3</td><td>6</td><td>9</td><td>12</td></tr></tbody></table>"
      ],
      "text/latex": [
       "\\begin{tabular}{r|cccc}\n",
       "\t& x1 & x2 & x3 & x4\\\\\n",
       "\t\\hline\n",
       "\t& Int64 & Int64 & Int64 & Int64\\\\\n",
       "\t\\hline\n",
       "\t3 & 3 & 6 & 9 & 12 \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/plain": [
       "\u001b[1mDataFrameRow\u001b[0m\n",
       "\u001b[1m Row \u001b[0m│\u001b[1m x1    \u001b[0m\u001b[1m x2    \u001b[0m\u001b[1m x3    \u001b[0m\u001b[1m x4    \u001b[0m\n",
       "\u001b[1m     \u001b[0m│\u001b[90m Int64 \u001b[0m\u001b[90m Int64 \u001b[0m\u001b[90m Int64 \u001b[0m\u001b[90m Int64 \u001b[0m\n",
       "─────┼────────────────────────────\n",
       "   3 │     3      6      9     12"
      ]
     },
     "execution_count": 85,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "last(er_df)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 86,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<p>DataFrameRow (4 columns)</p><table class=\"data-frame\"><thead><tr><th></th><th>x1</th><th>x2</th><th>x3</th><th>x4</th></tr><tr><th></th><th>Int64</th><th>Int64</th><th>Int64</th><th>Int64</th></tr></thead><tbody><tr><th>3</th><td>3</td><td>6</td><td>9</td><td>12</td></tr></tbody></table>"
      ],
      "text/latex": [
       "\\begin{tabular}{r|cccc}\n",
       "\t& x1 & x2 & x3 & x4\\\\\n",
       "\t\\hline\n",
       "\t& Int64 & Int64 & Int64 & Int64\\\\\n",
       "\t\\hline\n",
       "\t3 & 3 & 6 & 9 & 12 \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/plain": [
       "\u001b[1mDataFrameRow\u001b[0m\n",
       "\u001b[1m Row \u001b[0m│\u001b[1m x1    \u001b[0m\u001b[1m x2    \u001b[0m\u001b[1m x3    \u001b[0m\u001b[1m x4    \u001b[0m\n",
       "\u001b[1m     \u001b[0m│\u001b[90m Int64 \u001b[0m\u001b[90m Int64 \u001b[0m\u001b[90m Int64 \u001b[0m\u001b[90m Int64 \u001b[0m\n",
       "─────┼────────────────────────────\n",
       "   3 │     3      6      9     12"
      ]
     },
     "execution_count": 86,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "er_df[end]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "As `DataFrameRows` objects keeps connection to the parent data frame you can get the columns of the parent using `getproperty`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 87,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3-element Array{Int64,1}:\n",
       " 1\n",
       " 2\n",
       " 3"
      ]
     },
     "execution_count": 87,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "er_df.x1"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Flattening a data frame"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Occasionally you have a data frame whose one column is a vector of collections. You can expand (*flatten*) such a column using the `flatten` function"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 88,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table class=\"data-frame\"><thead><tr><th></th><th>a</th><th>b</th></tr><tr><th></th><th>Char</th><th>Any</th></tr></thead><tbody><p>3 rows × 2 columns</p><tr><th>1</th><td>a</td><td>[1, 2, 3]</td></tr><tr><th>2</th><td>b</td><td>[4, 5]</td></tr><tr><th>3</th><td>c</td><td>6</td></tr></tbody></table>"
      ],
      "text/latex": [
       "\\begin{tabular}{r|cc}\n",
       "\t& a & b\\\\\n",
       "\t\\hline\n",
       "\t& Char & Any\\\\\n",
       "\t\\hline\n",
       "\t1 & a & [1, 2, 3] \\\\\n",
       "\t2 & b & [4, 5] \\\\\n",
       "\t3 & c & 6 \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/plain": [
       "\u001b[1m3×2 DataFrame\u001b[0m\n",
       "\u001b[1m Row \u001b[0m│\u001b[1m a    \u001b[0m\u001b[1m b         \u001b[0m\n",
       "\u001b[1m     \u001b[0m│\u001b[90m Char \u001b[0m\u001b[90m Any       \u001b[0m\n",
       "─────┼─────────────────\n",
       "   1 │ a     [1, 2, 3]\n",
       "   2 │ b     [4, 5]\n",
       "   3 │ c     6"
      ]
     },
     "execution_count": 88,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = DataFrame(a = 'a':'c', b = [[1, 2, 3], [4, 5], 6])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 89,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table class=\"data-frame\"><thead><tr><th></th><th>a</th><th>b</th></tr><tr><th></th><th>Char</th><th>Int64</th></tr></thead><tbody><p>6 rows × 2 columns</p><tr><th>1</th><td>a</td><td>1</td></tr><tr><th>2</th><td>a</td><td>2</td></tr><tr><th>3</th><td>a</td><td>3</td></tr><tr><th>4</th><td>b</td><td>4</td></tr><tr><th>5</th><td>b</td><td>5</td></tr><tr><th>6</th><td>c</td><td>6</td></tr></tbody></table>"
      ],
      "text/latex": [
       "\\begin{tabular}{r|cc}\n",
       "\t& a & b\\\\\n",
       "\t\\hline\n",
       "\t& Char & Int64\\\\\n",
       "\t\\hline\n",
       "\t1 & a & 1 \\\\\n",
       "\t2 & a & 2 \\\\\n",
       "\t3 & a & 3 \\\\\n",
       "\t4 & b & 4 \\\\\n",
       "\t5 & b & 5 \\\\\n",
       "\t6 & c & 6 \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/plain": [
       "\u001b[1m6×2 DataFrame\u001b[0m\n",
       "\u001b[1m Row \u001b[0m│\u001b[1m a    \u001b[0m\u001b[1m b     \u001b[0m\n",
       "\u001b[1m     \u001b[0m│\u001b[90m Char \u001b[0m\u001b[90m Int64 \u001b[0m\n",
       "─────┼─────────────\n",
       "   1 │ a         1\n",
       "   2 │ a         2\n",
       "   3 │ a         3\n",
       "   4 │ b         4\n",
       "   5 │ b         5\n",
       "   6 │ c         6"
      ]
     },
     "execution_count": 89,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "flatten(df, :b)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Only one row"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`only` from Julia Base is also supported in DataFrames.jl and succeeds if the data frame has only one row, in which case it is returned."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 90,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table class=\"data-frame\"><thead><tr><th></th><th>a</th></tr><tr><th></th><th>Int64</th></tr></thead><tbody><p>1 rows × 1 columns</p><tr><th>1</th><td>1</td></tr></tbody></table>"
      ],
      "text/latex": [
       "\\begin{tabular}{r|c}\n",
       "\t& a\\\\\n",
       "\t\\hline\n",
       "\t& Int64\\\\\n",
       "\t\\hline\n",
       "\t1 & 1 \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/plain": [
       "\u001b[1m1×1 DataFrame\u001b[0m\n",
       "\u001b[1m Row \u001b[0m│\u001b[1m a     \u001b[0m\n",
       "\u001b[1m     \u001b[0m│\u001b[90m Int64 \u001b[0m\n",
       "─────┼───────\n",
       "   1 │     1"
      ]
     },
     "execution_count": 90,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = DataFrame(a=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 91,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<p>DataFrameRow (1 columns)</p><table class=\"data-frame\"><thead><tr><th></th><th>a</th></tr><tr><th></th><th>Int64</th></tr></thead><tbody><tr><th>1</th><td>1</td></tr></tbody></table>"
      ],
      "text/latex": [
       "\\begin{tabular}{r|c}\n",
       "\t& a\\\\\n",
       "\t\\hline\n",
       "\t& Int64\\\\\n",
       "\t\\hline\n",
       "\t1 & 1 \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/plain": [
       "\u001b[1mDataFrameRow\u001b[0m\n",
       "\u001b[1m Row \u001b[0m│\u001b[1m a     \u001b[0m\n",
       "\u001b[1m     \u001b[0m│\u001b[90m Int64 \u001b[0m\n",
       "─────┼───────\n",
       "   1 │     1"
      ]
     },
     "execution_count": 91,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "only(df)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 92,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table class=\"data-frame\"><thead><tr><th></th><th>a</th></tr><tr><th></th><th>Int64</th></tr></thead><tbody><p>2 rows × 1 columns</p><tr><th>1</th><td>1</td></tr><tr><th>2</th><td>1</td></tr></tbody></table>"
      ],
      "text/latex": [
       "\\begin{tabular}{r|c}\n",
       "\t& a\\\\\n",
       "\t\\hline\n",
       "\t& Int64\\\\\n",
       "\t\\hline\n",
       "\t1 & 1 \\\\\n",
       "\t2 & 1 \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/plain": [
       "\u001b[1m2×1 DataFrame\u001b[0m\n",
       "\u001b[1m Row \u001b[0m│\u001b[1m a     \u001b[0m\n",
       "\u001b[1m     \u001b[0m│\u001b[90m Int64 \u001b[0m\n",
       "─────┼───────\n",
       "   1 │     1\n",
       "   2 │     1"
      ]
     },
     "execution_count": 92,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df2 = repeat(df, 2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 93,
   "metadata": {},
   "outputs": [
    {
     "ename": "LoadError",
     "evalue": "ArgumentError: data frame must contain exactly 1 row",
     "output_type": "error",
     "traceback": [
      "ArgumentError: data frame must contain exactly 1 row",
      "",
      "Stacktrace:",
      " [1] only(::DataFrame) at D:\\AppData\\.julia\\packages\\DataFrames\\X0xNW\\src\\abstractdataframe\\abstractdataframe.jl:447",
      " [2] top-level scope at In[93]:1",
      " [3] include_string(::Function, ::Module, ::String, ::String) at .\\loading.jl:1091"
     ]
    }
   ],
   "source": [
    "only(df2)"
   ]
  }
 ],
 "metadata": {
  "@webio": {
   "lastCommId": null,
   "lastKernelId": null
  },
  "kernelspec": {
   "display_name": "Julia 1.5.3",
   "language": "julia",
   "name": "julia-1.5"
  },
  "language_info": {
   "file_extension": ".jl",
   "mimetype": "application/julia",
   "name": "julia",
   "version": "1.5.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
